-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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
Readonly error.code has ecosystem impact. #15658
Comments
There was some discussion about that in the PR introducing internal/errors: #11220 (review) /cc @jasnell |
Yes, the read only was intentional in order to explicitly prevent blind overriding. I believe the property is still configurable tho. It's been a while tho so I may be wrong |
This applies to CJS code as well, right? Is there a user-land scenario in mind, around augmenting Node specific errors, that you're wanting to prevent? I'm wondering if the user-land code should have to worry about it. To user-land code an error object is an error object. It could be a syntax error, or some other kind of error, and now code will have to branch for Node specific error objects or handle all error objects as tricky ones (which I'd assume is not the usual case). |
I'm not against changing it. There is a side effect in that the code is used in the name property, so it's not entirely free |
The symbol prop is used in the |
I would be +1 on changing. I've seen usage of overwriting Error#code some. |
What I mean is that changing code would make it out of sync with the name. We should decide whether those should be kept in sync automatically. |
Since the |
That's the answer I'd be hoping for ;) |
Proposed quick fix in #15694 |
Userland code can break if it depends on a mutable `code` property for errors. Allow users to change the `code` property but do not propagate changes to the error `name`. Additionally, make `message` and `name` consistent with `Error` object (non-enumerable). Test that `console.log()` and `.toString()` calls on internal `Error` objects with mutated properties have analogous results with the standard ECMAScript `Error` objects. Fixes: nodejs#15658
Userland code can break if it depends on a mutable `code` property for errors. Allow users to change the `code` property but do not propagate changes to the error `name`. Additionally, make `message` and `name` consistent with `Error` object (non-enumerable). Test that `console.log()` and `.toString()` calls on internal `Error` objects with mutated properties have analogous results with the standard ECMAScript `Error` objects. Fixes: nodejs#15658
For internal errors, make `code` and `name` settable while keeping them non-own properties by default. Fixes: nodejs#15658
For internal errors, make `code` and `name` settable while keeping them non-own properties by default. PR-URL: nodejs#15694 Fixes: nodejs#15658 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Userland code can break if it depends on a mutable `code` property for errors. Allow users to change the `code` property but do not propagate changes to the error `name`. Additionally, make `message` and `name` consistent with `Error` object (non-enumerable). Test that `console.log()` and `.toString()` calls on internal `Error` objects with mutated properties have analogous results with the standard ECMAScript `Error` objects. PR-URL: nodejs/node#15694 Fixes: nodejs/node#15658 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
For internal errors, make `code` and `name` settable while keeping them non-own properties by default. PR-URL: nodejs/node#15694 Fixes: nodejs/node#15658 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Userland code can break if it depends on a mutable `code` property for errors. Allow users to change the `code` property but do not propagate changes to the error `name`. Additionally, make `message` and `name` consistent with `Error` object (non-enumerable). Test that `console.log()` and `.toString()` calls on internal `Error` objects with mutated properties have analogous results with the standard ECMAScript `Error` objects. PR-URL: nodejs#15694 Fixes: nodejs#15658 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
For internal errors, make `code` and `name` settable while keeping them non-own properties by default. PR-URL: nodejs#15694 Fixes: nodejs#15658 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Userland code can break if it depends on a mutable `code` property for errors. Allow users to change the `code` property but do not propagate changes to the error `name`. Additionally, make `message` and `name` consistent with `Error` object (non-enumerable). Test that `console.log()` and `.toString()` calls on internal `Error` objects with mutated properties have analogous results with the standard ECMAScript `Error` objects. Backport-PR-URL: #16078 PR-URL: #15694 Fixes: #15658 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
For internal errors, make `code` and `name` settable while keeping them non-own properties by default. Backport-PR-URL: #16078 PR-URL: #15694 Fixes: #15658 Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
I know internal/errors usage is picking up in Node core so I thought I'd give a heads up on something I've seen in the wild. It looks like folks are adding
error.code
properties which will error with theinternal/errors
sinceerror.code
is readonly.Is being readonly intentional?
The text was updated successfully, but these errors were encountered: