Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34.3k
assert: improve ifError#18247
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
assert: improve ifError #18247
Uh oh!
There was an error while loading. Please reload this page.
Conversation
BridgeAR commented Jan 19, 2018 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
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.
What do others think about actually throwing in such a case? I personally think it would be best to only accept null and undefined.
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.
I agree, it's already semver-major so let's do it. Can you also update the PR description with this change?
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.
Done.
BridgeAR commented Jan 19, 2018
mcollina left a comment
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.
I'm thinking this might not be a good idea.
If an error we didn't want is passed, I think we prefer to see the original stacktrace and not the new one.
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.
if you remove await there is no need for this to be an async function.
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.
Hm, true. I am not sure why it was a async function in the first place. I guess a oversight.
BridgeAR commented Jan 19, 2018
@mcollina about the changed stack trace: you should have both. You can access the original stack trace by checking the I could also combine the stack traces (I thought about it before but I rejected it again) if that feels better to others. |
mcollina commented Jan 19, 2018
If you put it in |
BridgeAR commented Jan 22, 2018
@mcollina I rewrote this to extend the actual error with the necessary frames. So now you get a combined stack that is way more informative than before. |
BridgeAR commented Jan 23, 2018
lib/assert.js Outdated
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.
the goal of this code is not really clear, can you add some comments?
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.
Done.
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.
I would prefer a test showing a full stack trace, rather than this check. It would mean future edits are easier to understand and fix.
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.
I added a separate test to check for the stack trace and minimized this test to the necessary parts.
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.
I agree, it's already semver-major so let's do it. Can you also update the PR description with this change?
It is hard to know where ifError is actually triggered due to the original error being thrown. This changes it by wrapping the original error in a AssertionError. This has the positive effect of also making clear that it is indeed a assertion function that triggered that error. The original stack can still be accessed by checking the `actual` property.
Destructure the necessary Error classes from internal/errors. This improves the readability of the error creation.
This makes `assert.ifError` stricter by only accepting `null` and `undefined` from now on. Before any truthy value was accepted.
58d658c to 34f02d9Compare
mcollina left a comment
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.
LGTM
It is hard to know where ifError is actually triggered due to the original error being thrown. This changes it by wrapping the original error in a AssertionError. This has the positive effect of also making clear that it is indeed a assertion function that triggered that error. The original stack can still be accessed by checking the `actual` property. PR-URL: nodejs#18247 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
Destructure the necessary Error classes from internal/errors. This improves the readability of the error creation. PR-URL: nodejs#18247 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
This makes `assert.ifError` stricter by only accepting `null` and `undefined` from now on. Before any truthy value was accepted. PR-URL: nodejs#18247 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
BridgeAR commented Jan 24, 2018
Landed in 7a23fc0...e65a6e8 |
Trott commented Jan 25, 2018
Looks like this may have landed without a clean CI run? In any event, the message test added here seems to be failing 100% of the time on Windows CI. (Am I wrong somehow about that?) Is there a PR to fix that or should we revert until it's fixed? |
Trott commented Jan 25, 2018
Oh, I see the problem. It's expecting forward slashes, but on Windows, the path separator is (of course) backslashes. Opening a PR to fix. |
apapirovski commented Jan 25, 2018
Destructure the necessary Error classes from internal/errors. This improves the readability of the error creation. PR-URL: nodejs#18247 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
Destructure the necessary Error classes from internal/errors. This improves the readability of the error creation. Backport-PR-URL: #19230 PR-URL: #18247 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
Destructure the necessary Error classes from internal/errors. This improves the readability of the error creation. Backport-PR-URL: #19230 PR-URL: #18247 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
It is hard to know where ifError is actually triggered due to the original error being thrown. This changes it by wrapping the original error in a AssertionError. This has the positive effect of also making clear that it is indeed a assertion function that triggered that error. The original stack can still be accessed by checking the `actual` property. PR-URL: nodejs#18247 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
Destructure the necessary Error classes from internal/errors. This improves the readability of the error creation. PR-URL: nodejs#18247 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
This makes `assert.ifError` stricter by only accepting `null` and `undefined` from now on. Before any truthy value was accepted. PR-URL: nodejs#18247 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
It is hard to know where
ifErroris actually triggered due to theoriginal error being thrown.
This changes it by wrapping the original error in a AssertionError.
This has the positive effect of also making clear that it is indeed
a assertion function that triggered that error.
The original stack can still be accessed by checking the
actualproperty.
Show only the Error class and not
errors.AssertionError.Make
ifErrorstricter by only acceptingnullandundefinedfrom now on.Before any truthy value was accepted.
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
assert