-
Notifications
You must be signed in to change notification settings - Fork 450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace numeric error codes with strings #309
Conversation
ddd66fe
to
12ad4a8
Compare
I've done this PR in a relatively "dumb" way, just blindly swapping out numeric codes for strings as I saw fit. While we're here, I think it would be good to think about:
|
As a rough rule of thumb, let's group object formatting issues under single codes, but for any user input (eg |
Let's go ahead with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also add something to the README
that talks about errors a consumer is likely to run into, and what do about them:
ERR_OP_SUBMIT_REJECTED
(normal - for telling client to roll back)ERR_OP_ALREADY_SUBMITTED
(normal - the middleware abuses it to stop all further execution by looking like an error, but then the agent just swallows it because it's non-fatal)ERR_SUBMIT_TRANSFORM_OPS_NOT_FOUND
ERR_MAX_SUBMIT_RETRIES_EXCEEDED
ERR_DOC_ALREADY_CREATED
ERR_DOC_ALREADY_DELETED
ERR_DOC_TYPE_NOT_RECOGNISED
(Advanced use:)ERR_OP_NOT_ALLOWED_IN_PROJECTION
ERR_DEFAULT_TYPE_MISMATCH
fea81ba
to
1da399e
Compare
Fixes #287 Fixes #198 This is a breaking change that moves us from using numeric error codes to string-based codes [similar to Node][1]. The motivation for this is: - more descriptive error codes - stop implying that errors can be broadly classified together (in the same way that HTTP errors might) This change also exposes these codes on `ShareDBError.code`, so that they are easily discoverable, and can be referenced by consumers for programmatic error handling. [1]: https://nodejs.org/api/errors.html#nodejs-error-codes
This change aims to reword our new error codes according to review comments. The main changes are: - Prefix all code keys with `ERR_` - Rename to follow the <subject>_<state> format - Tweak some error code specificity - Provide a bit more context with some error messages
- Add documentation for common errors - Americanize spelling - Add a special error for invalid Milestone DB arguments
1da399e
to
6283301
Compare
While we're here, let's also replace all of our anonymous error objects with instances of an actual In short we should:
|
This change drops our dependence on `make-error`, and instead implements our own simple `ShareDBError` class, which extends `Error`. We also wrap all anonymous error objects in this `ShareDBError`, so that its type can be checked by consumers.
Fixes #287
Fixes #198
This is a breaking change that moves us from using numeric error codes
to string-based codes similar to Node.
The motivation for this is:
same way that HTTP errors might)
This change also exposes these codes on
ShareDBError.code
, so thatthey are easily discoverable, and can be referenced by consumers for
programmatic error handling.