Skip to content
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

errors: make sure all Node.js errors show their properties #29677

Closed
wants to merge 2 commits into from

Conversation

BridgeAR
Copy link
Member

This improves Node.js errors by always showing the attached properties
when inspecting such an error. This applies especially to SystemError.
It did often not show any properties but now all properties will be
visible.
This is done in a mainly backwards compatible way. Instead of using
prototype getters and setters, the property is now set directly on the
error.

Note: the custom inspect function is necessary for the SystemError to keep the old getter/setter behavior intact .

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Sep 23, 2019
This improves Node.js errors by always showing the attached properties
when inspecting such an error. This applies especially to SystemError.
It did often not show any properties but now all properties will be
visible.
This is done in a mainly backwards compatible way. Instead of using
prototype getters and setters, the property is now set directly on the
error.
@nodejs-github-bot
Copy link
Collaborator

@joyeecheung
Copy link
Member

One question regarding err.code: do we still need to show this after we put it into the message line?

@BridgeAR
Copy link
Member Author

I personally think we should, since it's an actual property and the user would otherwise not know about that. It's possible to check for the code in that case.

It is of course somewhat redundant but I think for now we should just show both.

@BridgeAR BridgeAR added the review wanted PRs that need reviews. label Sep 25, 2019
@Trott
Copy link
Member

Trott commented Oct 1, 2019

@nodejs/collaborators This could use some reviews.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

It is not clear why some operations are done in a specific way. This
should be clarified to potentially simplify the implementation.
@BridgeAR
Copy link
Member Author

BridgeAR commented Oct 1, 2019

@mcollina PTAL (I added a TODO comment as suggested by @jasnell #29677 (comment)).

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 1, 2019
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@Trott
Copy link
Member

Trott commented Oct 2, 2019

Wondering if this might be more breaking than we realize. Out of caution, here's a CITGM (with debian-8 unchecked for $REASONS): https://ci.nodejs.org/view/Node.js-citgm/job/citgm-smoker/2027/ (queued)

Comment on lines +164 to +167
'[Error [ERR_SCRIPT_EXECUTION_INTERRUPTED]: ' +
'Script execution was interrupted by `SIGINT`] {',
" code: 'ERR_SCRIPT_EXECUTION_INTERRUPTED'",
'}',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did this test in particular need to change? is there something unusual about how this test works?

Copy link
Member Author

@BridgeAR BridgeAR Oct 3, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The difference is that the code property became enumerable. That seems important so that users become aware that it's an actual property, not only part of .stack.

Mostly we just do not check what properties exist but only verify that specific properties contain specific values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words, because no other tests inspect .stack this way?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the stack that is changed here. It's the output when inspecting the error (e.g., using console.log or util.inspect). The reason is that only enumerable properties are inspected by default and others are ignored.

We rarely inspect errors in tests. Mostly we just check for the properties existence and their values. That also works with non-enumerable properties.

@Trott
Copy link
Member

Trott commented Oct 3, 2019

CITGM looks good.

@Trott
Copy link
Member

Trott commented Oct 3, 2019

@nodejs/tsc What's the semver-ity of this? Patch? Major? Minor even?

@BridgeAR
Copy link
Member Author

BridgeAR commented Oct 3, 2019

@Trott I would say it's a patch, since no property was added or removed and they are also writable and configurable as before. We might call it semver-minor due to the change in enumerable properties but it seems more like a fix to me. We do enumerable properties on other system errors and also on other error types. Just the code property was an exception to that rule (but it is the most common property).

@Trott
Copy link
Member

Trott commented Oct 3, 2019

Going to land as patch. semver-* label can always be added after landing if anyone disagrees.

Trott pushed a commit that referenced this pull request Oct 3, 2019
This improves Node.js errors by always showing the attached properties
when inspecting such an error. This applies especially to SystemError.
It did often not show any properties but now all properties will be
visible.

This is done in a mainly backwards compatible way. Instead of using
prototype getters and setters, the property is now set directly on the
error.

PR-URL: #29677
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
@Trott Trott added the notable-change PRs with changes that should be highlighted in changelogs. label Oct 3, 2019
@Trott
Copy link
Member

Trott commented Oct 3, 2019

Landed in 500720f

@Trott Trott closed this Oct 3, 2019
BridgeAR added a commit that referenced this pull request Oct 9, 2019
This improves Node.js errors by always showing the attached properties
when inspecting such an error. This applies especially to SystemError.
It did often not show any properties but now all properties will be
visible.

This is done in a mainly backwards compatible way. Instead of using
prototype getters and setters, the property is now set directly on the
error.

PR-URL: #29677
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Oct 10, 2019
@BridgeAR BridgeAR deleted the awlays-show-error-properties branch January 20, 2020 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. errors Issues and PRs related to JavaScript errors originated in Node.js core. notable-change PRs with changes that should be highlighted in changelogs. review wanted PRs that need reviews.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants