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

assert: make sure throws is able to handle primitives #20482

Closed
wants to merge 1 commit into from

Conversation

BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented May 2, 2018

This fixes some possible issues with assert.throws in combination
with an validation object. It will now properly handle primitive
values being thrown as error.

It also makes sure the generatedMessage property is properly set
if assert.throws is used in combination with an validation object
and improves the error performance in such cases by only creating
the error once.

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 assert Issues and PRs related to the assert subsystem. label May 2, 2018
@BridgeAR
Copy link
Member Author

BridgeAR commented May 2, 2018

@BridgeAR
Copy link
Member Author

BridgeAR commented May 3, 2018

This currently depends on #20487 to land first.
Update: this is now unblocked.

@addaleax addaleax added the blocked PRs that are blocked by other issues or PRs. label May 6, 2018
@BridgeAR BridgeAR removed the blocked PRs that are blocked by other issues or PRs. label May 7, 2018
@BridgeAR
Copy link
Member Author

BridgeAR commented May 7, 2018

New CI https://ci.nodejs.org/job/node-test-pull-request/14696/

@nodejs/testing PTAL

@addaleax
Copy link
Member

addaleax commented May 7, 2018

As I understand it, this makes assert.throws(() => { throw 4; }, 4); an error. It seems like an edge case, and validation doesn’t work right now (any right-hand side is being accepted right now), but is there any reason to not make it work?

@BridgeAR
Copy link
Member Author

BridgeAR commented May 7, 2018

@addaleax that is indeed an edge case and actually a side effect of this fix.

It is meant to fix:

assert.throws(() => { throw 4; }, { message: '4' })
TypeError: Cannot use 'in' operator to search for 'message' in 4
    at compareExceptionKey (assert.js:374:13)

I will work around it to prevent it from being semver-major.

@BridgeAR
Copy link
Member Author

BridgeAR commented May 7, 2018

@BridgeAR
Copy link
Member Author

BridgeAR commented May 9, 2018

@nodejs/collaborators PTAL

@vsemozhetbyt vsemozhetbyt added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 9, 2018
This fixes some possible issues with `assert.throws` in combination
with an validation object. It will now properly handle primitive
values being thrown as error.

It also makes sure the `generatedMessage` property is properly set
if `assert.throws` is used in combination with an validation object
and improves the error performance in such cases by only creating
the error once.
@BridgeAR
Copy link
Member Author

Rebased due to conflicts.

CI before landing: https://ci.nodejs.org/job/node-test-pull-request/14781/

BridgeAR added a commit to BridgeAR/node that referenced this pull request May 10, 2018
This fixes some possible issues with `assert.throws` and
`assert.rejects` in combination with an validation object. It will
now properly handle primitive values being thrown as error.

It also makes sure the `generatedMessage` property is properly set
if `assert.throws` or `assert.rejects` is used in combination with
an validation object and improves the error performance in such cases
by only creating the error once.

In addition it will fix detecting regular expressions from a different
context such as n-api that are passed through as validator for
`assert.throws` or `assert.rejects`. Until now those were not tested.

PR-URL: nodejs#20482
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
@BridgeAR
Copy link
Member Author

Landed in 560925f

@BridgeAR BridgeAR closed this May 10, 2018
targos pushed a commit that referenced this pull request May 12, 2018
This fixes some possible issues with `assert.throws` and
`assert.rejects` in combination with an validation object. It will
now properly handle primitive values being thrown as error.

It also makes sure the `generatedMessage` property is properly set
if `assert.throws` or `assert.rejects` is used in combination with
an validation object and improves the error performance in such cases
by only creating the error once.

In addition it will fix detecting regular expressions from a different
context such as n-api that are passed through as validator for
`assert.throws` or `assert.rejects`. Until now those were not tested.

PR-URL: #20482
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
@addaleax addaleax mentioned this pull request May 14, 2018
@BridgeAR BridgeAR deleted the fix-assertion-things branch January 20, 2020 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
assert Issues and PRs related to the assert subsystem. author ready PRs that have at least one approval, no pending requests for changes, and a CI started.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants