Skip to content

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

Closed
BridgeAR wants to merge 1 commit into
nodejs:masterfrom
BridgeAR:fix-assertion-things
Closed

assert: make sure throws is able to handle primitives#20482
BridgeAR wants to merge 1 commit into
nodejs:masterfrom
BridgeAR:fix-assertion-things

Conversation

@BridgeAR

@BridgeARBridgeAR commented May 2, 2018

Copy link
Copy Markdown
Member

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-botnodejs-github-bot added the assert Issues and PRs related to the assert subsystem. label May 2, 2018
@BridgeAR

BridgeAR commented May 2, 2018

Copy link
Copy Markdown
MemberAuthor

@BridgeAR

BridgeAR commented May 3, 2018

Copy link
Copy Markdown
MemberAuthor

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

@addaleaxaddaleax added the blocked PRs that are blocked by other issues or PRs. label May 6, 2018
@BridgeARBridgeAR removed the blocked PRs that are blocked by other issues or PRs. label May 7, 2018
@BridgeAR
BridgeARforce-pushed the fix-assertion-things branch from c3026d9 to 6b1f886CompareMay 7, 2018 11:24
@BridgeAR

Copy link
Copy Markdown
MemberAuthor

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

@nodejs/testing PTAL

@addaleax

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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

It is meant to fix:

assert.throws(()=>{throw4;},{message: '4'})
TypeError: Cannotuse 'in' operator to search for 'message' in4atcompareExceptionKey(assert.js:374:13)

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

@BridgeAR

Copy link
Copy Markdown
MemberAuthor

@BridgeAR

Copy link
Copy Markdown
MemberAuthor

@nodejs/collaborators PTAL

@vsemozhetbytvsemozhetbyt 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
BridgeARforce-pushed the fix-assertion-things branch from ee4907a to 34b4818CompareMay 10, 2018 11:25
@BridgeAR

Copy link
Copy Markdown
MemberAuthor

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 <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@BridgeAR

Copy link
Copy Markdown
MemberAuthor

Landed in 560925f

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 <jasnell@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@addaleaxaddaleax mentioned this pull request May 14, 2018
@BridgeAR
BridgeAR deleted the fix-assertion-things branch January 20, 2020 11:31
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.author readyPRs 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

@BridgeAR@addaleax@jasnell@targos@vsemozhetbyt@nodejs-github-bot