Skip to content

assert: improve AssertionError in case of "Errors" - #15025

Closed
BridgeAR wants to merge 1 commit into
nodejs:masterfrom
BridgeAR:improve-assertion-error
Closed

assert: improve AssertionError in case of "Errors"#15025
BridgeAR wants to merge 1 commit into
nodejs:masterfrom
BridgeAR:improve-assertion-error

Conversation

@BridgeAR

Copy link
Copy Markdown
Member

Showing the stack trace in a error message obfuscates the actual
message and should not be visible therefore.

I think this is actually part of the assert subsystem even though the AssertionError is placed in the internal/errors.

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
Affected core subsystem(s)

assert

Showing the stack trace in a error message obfuscates the actual
message and should not be visible therefore.
@nodejs-github-botnodejs-github-bot added the errors Issues and PRs related to JavaScript errors originated in Node.js core. label Aug 25, 2017
@BridgeARBridgeAR added the assert Issues and PRs related to the assert subsystem. label Aug 25, 2017
@BridgeAR

Copy link
Copy Markdown
MemberAuthor

@jasnelljasnell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is likely a semver-major change

@jasnelljasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Aug 25, 2017
@BridgeAR

Copy link
Copy Markdown
MemberAuthor

@jasnell I personally would consider it as a bugfix as I highly doubt this was really anticipated and ever wanted behavior.

@jasnell

Copy link
Copy Markdown
Member

I would tend to agree. Let's see if others in @nodejs/ctc do also :)

@Trott

Copy link
Copy Markdown
Member

I agree it's a bugfix, but a CITGM run for good measure wouldn't be a terrible idea.

@jasnell

Copy link
Copy Markdown
Member

When I'm actually able to get to CI I'll give it a run.

if (message) {
super(message);
} else {
if (actual && actual.stack && actual instanceof Error)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Isn't actual instanceof Error itself enough?

@BridgeARBridgeARAug 26, 2017

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

It is but it has a performance implication (it might not be important because it is only about errors but it is something that I always like to consider).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmmm.. actually, I believe .stack is a getter isn't it? It will have a performance impact also.

@BridgeARBridgeARAug 26, 2017

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

@jasnell util.inspect will look at the stack as well. The first call to the stack is heavy and it does not matter if it is done here or later on (well it is actually not anymore as we only pass a string through instead of the error but the performance for the error will stay the same as before and the average case wont have any negative hit).

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

So yes, it would be faster for Error objects (the instanceof check is added on top of the stack access) but slower for the average case.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yeah. Hmm. It's likely fine. Doing it the same way internal/util isError does would likely be ok also but I'm good with it :)

@BridgeAR

Copy link
Copy Markdown
MemberAuthor

@BridgeAR

Copy link
Copy Markdown
MemberAuthor

Ping @nodejs/ctc

@BridgeAR

Copy link
Copy Markdown
MemberAuthor

Ping @nodejs/tsc PTAL

@BridgeAR

Copy link
Copy Markdown
MemberAuthor

It would also be nice to get a comment about

@BridgeAR: I personally would consider it as a bugfix as I highly doubt this was really anticipated and ever wanted behavior.

@jasnell: I would tend to agree. Let's see if others in @nodejs/ctc do also :)

@BridgeAR

Copy link
Copy Markdown
MemberAuthor

PTAL @nodejs/tsc (semver-patch / semver-major)

@targos

targos commented Sep 13, 2017

Copy link
Copy Markdown
Member

+1 for bug fix / semver-patch

@joyeecheung

Copy link
Copy Markdown
Member

+1 for semver-patch

@jasnelljasnell removed the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 14, 2017
@jasnell

jasnell commented Sep 14, 2017

Copy link
Copy Markdown
Member

@BridgeAR

Copy link
Copy Markdown
MemberAuthor

Thanks a lot! Landed in 2e8217c

BridgeAR added a commit that referenced this pull request Sep 15, 2017
Showing the stack trace in a error message obfuscates the actual
message and should not be visible therefore.
PR-URL: #15025
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 17, 2017
Showing the stack trace in a error message obfuscates the actual
message and should not be visible therefore.
PR-URL: nodejs/node#15025
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@jasnell

Copy link
Copy Markdown
Member

This does not land cleanly on v8.x, a backport would be needed.

@BridgeAR

Copy link
Copy Markdown
MemberAuthor

This should land cleanly as soon as #14167 got in. I open a backport for that in a few minutes.

jasnell pushed a commit that referenced this pull request Sep 21, 2017
Showing the stack trace in a error message obfuscates the actual
message and should not be visible therefore.
PR-URL: #15025
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@jasnell

Copy link
Copy Markdown
Member

landed in v8.x-staging. Thank you!

Qard pushed a commit to Qard/ayo that referenced this pull request Sep 21, 2017
Showing the stack trace in a error message obfuscates the actual
message and should not be visible therefore.
PR-URL: nodejs/node#15025
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
@MylesBorins

Copy link
Copy Markdown
Contributor

This does not land cleanly in LTS. Please feel free to manually backport by following the guide. Please also feel free to replace do-not-land if it is being backported

@apapirovskiapapirovski mentioned this pull request Dec 9, 2017
4 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

assertIssues and PRs related to the assert subsystem.errorsIssues and PRs related to JavaScript errors originated in Node.js core.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@BridgeAR@jasnell@Trott@targos@joyeecheung@MylesBorins@thefourtheye@nodejs-github-bot