Skip to content

Use undefined instead of error for non-existing records #76

@ghost

Description

This is a request for discussion about the semantics of db.get() when a key doesn't exist. Currently, an error with a non-enumerable type key is provided for missing keys:

db.get('does-not-exist', function (err, value) {
  console.log('err=', err);
  console.log('err.type=', err.type);
})

produces this output:

err= {}
err.type= NotFoundError

The error is not easy to inspect at a glance (a separate issue) and if you want to check for non-existence you've got to remember that the err.type for non-existence is NotFoundError.

Would it make more sense to just use undefined for the value and not go through the err parameter? undefined is already an invalid value to use for storage so it wouldn't conflict with anything unless there are some edge cases for custom valueEncodings I'm not aware of.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions