For example:
if (err.code === 'ERR_NOT_FOUND') // ..
This will allow us to:
- Change error messages without a major bump. Going forward, the semver contract will be on
code.
- Change the test suites of
levelup and abstract-leveldown to check expected errors by code, making it easier to align errors.
- Return specific errors from C++, because it aligns well with
napi_create_error(env, code, ...). E.g. leveldown can return a ERR_NOT_FOUND natively without the need for further wrapping in JS (although initially we'll still need that for backwards compat).
TBD:
- Does this remove the need for the current error types defined here?
- If not, will we need a mapping of codes to types?
- Should we restrict the codes to a known set, or allow modules (like
leveldown) to return arbitrary codes?
- Should the codes have a certain prefix, like
ERR_LEVEL_?
Ref Level/community#58
For example:
This will allow us to:
code.levelupandabstract-leveldownto check expected errors by code, making it easier to align errors.napi_create_error(env, code, ...). E.g.leveldowncan return aERR_NOT_FOUNDnatively without the need for further wrapping in JS (although initially we'll still need that for backwards compat).TBD:
leveldown) to return arbitrary codes?ERR_LEVEL_?Ref Level/community#58