-
Notifications
You must be signed in to change notification settings - Fork 30.2k
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: fix misformatted error message #11254
Conversation
Technically My thinking is that this doesn't violate the Locked API because it's a bug fix, even if we have a policy (at least at this time) to treat this particular type of bug fix like it's semver major. But a "sorry, semver major is semver major, deal with it" approach also makes sense. (In which case, I might see if there's a general sentiment to unlock the API but that's another conversation.) |
LGTM, and definitely seems related to #11200. |
lib/assert.js
Outdated
@@ -342,7 +342,7 @@ function _throws(shouldThrow, block, expected, message) { | |||
actual = _tryBlock(block); | |||
|
|||
message = (expected && expected.name ? ' (' + expected.name + ').' : '.') + | |||
(message ? ' ' + message : '.'); | |||
(message ? ' ' + message : ''); |
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.
shouldn't this end with .
when message
is truthy?
(message ? ` ${message}.` : '');
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.
Yes, unless message
is expected to already end with .
, so ¯\(ツ)/¯. And there should also be a :
rather than .
after expected
if message
is truthy.
Thinking about this some more and looking at the uses, I wonder if the thing to do is get rid of all the logic for appending .
in the first place. Nothing else appends .
. And this mostly only seems to do it wrong!
Current master results in messages like this:
AssertionError: Missing expected exception..
AssertionError: Missing expected exception. foo bar baz
wat?
Compare to assert.strictEqual()
which does not append .
:
AssertionError: 'a' === 'b'
AssertionError: foo bar baz
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.
@lpinca OK, I just pushed some improvements based on your comment. PTAL
Before: `Missing expected exception..` Afer: `Missing expected exception.`
This also makes sense imo, I think most error messages don't use |
|
Before: `Missing expected exception..` Afer: `Missing expected exception.` PR-URL: nodejs#11254 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
Landed in 0af4183 |
Before:
Missing expected exception..
Afer:
Missing expected exception.
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
assert