-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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: validate input stricter #20481
Conversation
719f3af
to
5eff6a5
Compare
Seems like this detected an issue in our tests where |
It also detected this error: bdf5be9#r28831219 |
This depends on #20487 to land first. |
@nodejs/testing |
(I imagine this should get a CITGM run? I mean, even if it only uncovers bugs in the packages, we probably want to get issues and PRs filed before releasing this.) |
5eff6a5
to
d1c2c46
Compare
I rebased, since this is now unblocked. CI https://ci.nodejs.org/job/node-test-pull-request/14697/ ✔️ |
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
This makes sure invalid `error` objects are not ignored when using `assert.throws` and `assert.rejects`.
d1c2c46
to
f8a9023
Compare
Rebased due to conflicts. CI before landing: https://ci.nodejs.org/job/node-test-pull-request/14784/ |
Landed in 21c3a40 |
This makes sure invalid `error` objects are not ignored when using `assert.throws` and `assert.rejects`. PR-URL: nodejs#20481 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
@@ -438,6 +433,9 @@ function expectedException(actual, expected, msg) { | |||
// as well. | |||
if (expected instanceof Error) { | |||
keys.push('name', 'message'); | |||
} else if (keys.length === 0) { | |||
throw new ERR_INVALID_ARG_VALUE('error', | |||
expected, 'may not be an empty object'); |
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.
is there any background on why this constraint was added?
It seems perfectly valid to me to do var sentinel = {}; assert.throws(() => { throw sentinel; }, sentinel, 'throws the sentinel');
, for example.
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.
Before this change, nothing would have been validated as the signature was about validating the properties of the object and there are no properties to validate.
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.
ahh ok, so there's no way to validate that a specific thing with identity is thrown?
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.
It's possible with the function validation: var sentinel = {}; assert.throws(() => { throw sentinel; }, (error) => { assert(error === sentinel, 'Sentinel should be thrown'); return true});
This makes sure invalid
error
objects are not ignored when usingassert.throws
andassert.rejects
.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes