-
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
doc: add warning to assert.doesNotThrow() #18699
Conversation
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
|
@ChALkeR I am also pretty sure people use it. The question is though if we want to encourage new people to use a pretty useless API that should be replaced with comments. And because it is used right now, I think a doc only deprecation is best in this case. |
@BridgeAR Note that chai implements this differently: http://chaijs.com/api/assert/#method_doesnotthrow
|
@ChALkeR yes, the chai implementation has a use case. Even though I am not not sold on testing explicitly against a type of error / message and accept all others. |
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 -1 to deprecating. Eliminating this from our tests is fine. If people want to use this API for whatever reason, that's their choice.
Even without deprecating, we could add a note to |
@ChALkeR I like that idea. |
doc/api/assert.md
Outdated
@@ -316,13 +316,19 @@ parameter is an instance of an [`Error`][] then it will be thrown instead of the | |||
<!-- YAML | |||
added: v0.1.21 | |||
changes: | |||
- version: REPLACEME | |||
pr-url: https://github.com/nodejs/node/pull/REPLAEME |
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.
Nit: typo REPLAEME
That holds true even after this documentation only deprecation. There will not be any warning what so ever. But people who try to find out how the assert module works will clearly see that this is actually not that useful. Only adding a regular comment does not solve the same as well because it is not that obvious. I tried to find a single use case but I could not find any. Not with any argument combination. That is why I suggest to doc-only deprecate the API. The |
Right, but a docs deprecation sort of means we're planning to runtime deprecate / remove it one day. |
I am not aware that this is written down anywhere. I do not see that as a necessary subsequent step. I personally would not want to remove this API (probably ever) because it is used too often. A runtime deprecation is probably also not in place for multiple more years out of my perspective. That might be evaluated again at some point of time but even then: to change the deprecation from documentation-only to something else someone has to open a PR for it and it would probably be denied. Therefore I would still like to land this as is. |
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 good with this as a docs-only deprecation does not require that we have to upgrade to to a runtime deprecation later. Although, I'd also be ok with just a docs comment also.
Ping @cjihrig |
I'm still -1 on an official docs deprecation, but am fine with something like @ChALkeR suggested. |
@cjihrig as far as I understand your reasons you were mainly against this ever becoming a Runtime deprecation, right? Because I believe there should be other ways to guarantee that than not deprecating this at all. |
doc/api/assert.md
Outdated
@@ -330,6 +330,11 @@ changes: | |||
Asserts that the function `block` does not throw an error. See | |||
[`assert.throws()`][] for more details. | |||
|
|||
Please note: Using `assert.doesNotThrow()` is not recommended because there is | |||
no benefit by catching an error and then rethrowing it. Instead, consider adding |
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.
Nit: by
-> to
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.
s/recommended/actually useful/
Given that we are not deprecating it and that there is no direct harm, I don't see a reason to recommend avoiding it. Comment vs assert.doesNotThrow
is pure stylistic.
A note that it doesn't do anything useful and could be replaced with a comment seems better fit, imo.
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 think we can do both. Say that it is not useful and therefore not recommended to use.
LGTM with @ChALkeR’s comment Edit, to maybe clarify a bit: API reference documentation is supposed to be more informative than instructive. It’s the same reason we avoid “you” in our documentation. |
Why? I've never really understood this. If you pick a random page from the std library of another language, they all seem to use "you" indiscriminately: Fundamentally we're instructing users of Node in how we think they should use the APIs we provide. Making the tone more formal (e.g. making everything passive) doesn't really change that. |
doc/api/assert.md
Outdated
Please note: Using `assert.doesNotThrow()` is not recommended because there is | ||
no benefit by catching an error and then rethrowing it. Instead, consider adding | ||
a comment next to the specific code path that should not throw and keep all | ||
error messages in your code as expressive as possible. |
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.
Nit: your
:-(
Perhaps
Instead, consider adding a comment next to the specific code path that should
not throw and keep add error messages as expressive as possible.
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.
@jasnell There's an error in your proposed text. I think the word add
should be deleted?
Comments addressed. Lite-CI https://ci.nodejs.org/job/node-test-pull-request-lite/232/ |
Please note: Using `assert.doesNotThrow()` is actually not useful because there | ||
is no benefit by catching an error and then rethrowing it. Instead, consider | ||
adding a comment next to the specific code path that should not throw and keep | ||
error messages as expressive as possible. |
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.
Suggested rewording ...
The `assert.doesNotThrow()` method is not as useful in practice as it may
first appear. Consider, instead, adding comments to the specific code paths
that should not throw errors and keep error messages as expressive as possible.
Using `assert.doesNotThrow()` has no benefit over adding a comment next to some code that should not throw. Therefore it is from now on discouraged to use it. PR-URL: nodejs#18699 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Landed in 8b69d4a |
Using `assert.doesNotThrow()` has no benefit over adding a comment next to some code that should not throw. Therefore it is from now on discouraged to use it. PR-URL: #18699 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
I removed the semver-minor label as that does not apply anymore since it is only a comment. |
Using `assert.doesNotThrow()` has no benefit over adding a comment next to some code that should not throw. Therefore it is from now on discouraged to use it. PR-URL: #18699 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Using `assert.doesNotThrow()` has no benefit over adding a comment next to some code that should not throw. Therefore it is from now on discouraged to use it. PR-URL: nodejs#18699 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Using `assert.doesNotThrow()` has no benefit over adding a comment next to some code that should not throw. Therefore it is from now on discouraged to use it. PR-URL: nodejs#18699 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Using `assert.doesNotThrow()` has no benefit over adding a comment next to some code that should not throw. Therefore it is from now on discouraged to use it. Backport-PR-URL: #22380 PR-URL: #18699 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gibson Fahnestock <[email protected]> Reviewed-By: Tiancheng "Timothy" Gu <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
Using
assert.doesNotThrow()
has no benefit over adding a commentnext to some code that should not throw. Therefore it is from now
on discouraged to use it.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
doc, assert