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: add warning about assert.doesNotReject #19462

Closed
wants to merge 1 commit into from

Conversation

BridgeAR
Copy link
Member

The usefulness of assert.doesNotReject is very limited and this
warns against the usage.

This keeps it in line with assert.doesNotThrow.

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

The usefulness of `assert.doesNotReject` is very limited and this
warns against the usage.
@nodejs-github-bot nodejs-github-bot added assert Issues and PRs related to the assert subsystem. doc Issues and PRs related to the documentations. labels Mar 20, 2018
@BridgeAR
Copy link
Member Author

Please note: Using `assert.doesNotReject()` is actually not useful because there
is little benefit by catching a rejection and then rejecting it again. Instead,
consider adding a comment next to the specific code path that should not reject
and keep error messages as expressive as possible.
Copy link
Member

Choose a reason for hiding this comment

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

Suggestions: Get rid of Please note: and keep the first sentence concise:

There is little benefit to using `assert.doesNotReject()`. Instead, consider adding a comment...

Copy link
Member Author

@BridgeAR BridgeAR Mar 20, 2018

Choose a reason for hiding this comment

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

In this specific case I would rather keep the Please note as I really want users to read this. That is also why it is placed prominently. And the text is currently similar to the one used in doesNotThrow, so I thought I just keep them aligned.

@apapirovski
Copy link
Member

apapirovski commented Mar 20, 2018

I'm not 100% certain this is a beneficial comment to add. Imagine I'm using some Promise API where I don't care about the return result, assert.doesNotReject is a more straight forward way of saying promiseGeneratingApi().catch(assert.fail); which also happens to work nicer with the async/await syntax. Ignore me.

@BridgeAR
Copy link
Member Author

@apapirovski I am not certain what the benefit of catching the rejection and rejecting it again is. Can you please elaborate? Your example is going to reject the same error that it caught without modifying it.

@apapirovski
Copy link
Member

@BridgeAR B'ah. I forgot it was all handled async anyway. I stopped following the development of that feature at some point. (In my mind we were throwing on nextTick.)

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

LGTM

@BridgeAR
Copy link
Member Author

Landed in 5d6d1fe

@BridgeAR BridgeAR closed this Mar 24, 2018
BridgeAR added a commit to BridgeAR/node that referenced this pull request Mar 24, 2018
The usefulness of `assert.doesNotReject` is very limited and this
warns against the usage.

PR-URL: nodejs#19462
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@targos
Copy link
Member

targos commented Apr 2, 2018

Should land in v9.x only if #18023 makes it.

BridgeAR added a commit to BridgeAR/node that referenced this pull request May 1, 2018
The usefulness of `assert.doesNotReject` is very limited and this
warns against the usage.

PR-URL: nodejs#19462
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@BridgeAR BridgeAR deleted the warn-again-does-not-reject branch April 1, 2019 23:39
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. doc Issues and PRs related to the documentations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants