-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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 AssertException, assign error code #12651
Conversation
|
Ooops! No, I misread it entirely and I'm totally wrong, I think. Ignore my comment! :-D |
@Trott ... heh... |
|
||
function truncate(s, n) { | ||
return s.slice(0, n); | ||
// TODO(jasnell): Consider moving AssertionError into internal/errors.js |
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: I dislike TODO
comments because they tend to confuse others rather than communicate clearly what's going on. See all the longstanding TODOs that we just can't seem to address and all the confusion it sows for people reading them in #4641 #4642 #4640
In this case, what are the considerations? I'd rather see this opened as a separate issue with full sentences and paragraphs explaining the issue.
On the other hand, bonus points for putting your name there so at least the reader knows who to ask.
You can totally ignore this nit, of course. But in the off-chance you agree, then please open an issue.
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 expected at least one person to ask about this one :-) ... if we think it's a good idea, then I can just add a commit to this PR that moves it. It would be a minimally invasive change and would allow us to simplify some of the code. I just didn't do it yet because I want to know if there are any objections before doing so.
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.
TODO
comments like this are still better than not having them, IMO.
SGTM in principle. Since this involves significant changes to |
I'll give the coverage run a go, but considering the fact that the tests had not previously caught that calling |
I know you're being facetious (I hope), but that won't stop me from saying: 100% coverage just means that all the code gets exercised, not that there are no unhelpful error messages or (for that matter) bugs. 100% coverage isn't a guarantee that everything is tested. But 90% coverage is a guarantee that not everything is tested. So let's keep it at 100%. :-) |
Yes I am being facetious ;-) ... I'm running the coverage report now |
@Trott ... updated! This should have 100% coverage on the |
Ping @Trott (and other @nodejs/ctc) |
No comment on the code but +1 to the idea. |
CI is failing. Something needs some adjusting.... |
Ah... yeah, non-obvious rebase conflict. Rebasing and updating now. |
cc5a090
to
5648ed5
Compare
CI is green. |
Using `assert.AssertException()` without the `new` keyword results in a non-intuitive error: ```js > assert.AssertionError({}) TypeError: Cannot assign to read only property 'name' of function 'function ok(value, message) { if (!value) fail(value, true, message, '==', assert.ok); }' at Function.AssertionError (assert.js:45:13) at repl:1:8 at realRunInThisContextScript (vm.js:22:35) at sigintHandlersWrap (vm.js:98:12) at ContextifyScript.Script.runInThisContext (vm.js:24:12) at REPLServer.defaultEval (repl.js:346:29) at bound (domain.js:280:14) at REPLServer.runBound [as eval] (domain.js:293:12) at REPLServer.onLine (repl.js:545:10) at emitOne (events.js:101:20) > ``` The `assert.AssertionError()` can only be used correctly with `new`, so this converts it into a proper ES6 class that will give an appropriate error message. This also associates the appropriate internal/errors code with all `assert.AssertionError` instances and updates the appropriate test cases.
5648ed5
to
8a70aa9
Compare
ping @nodejs/ctc ... I'd like to get this landed in time for 8.0.0 :-) |
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 and nice to see ongoing progress on supporting error codes.
Landed in 3f34ede |
Shouldn't it be "AssertionError" instead of "AssertException" in the commit message? |
doh! ok, we're still within the ten minutes so I'm going to push a fix |
fixed! |
Using `assert.AssertionError()` without the `new` keyword results in a non-intuitive error: ```js > assert.AssertionError({}) TypeError: Cannot assign to read only property 'name' of function 'function ok(value, message) { if (!value) fail(value, true, message, '==', assert.ok); }' at Function.AssertionError (assert.js:45:13) at repl:1:8 at realRunInThisContextScript (vm.js:22:35) at sigintHandlersWrap (vm.js:98:12) at ContextifyScript.Script.runInThisContext (vm.js:24:12) at REPLServer.defaultEval (repl.js:346:29) at bound (domain.js:280:14) at REPLServer.runBound [as eval] (domain.js:293:12) at REPLServer.onLine (repl.js:545:10) at emitOne (events.js:101:20) > ``` The `assert.AssertionError()` can only be used correctly with `new`, so this converts it into a proper ES6 class that will give an appropriate error message. This also associates the appropriate internal/errors code with all `assert.AssertionError` instances and updates the appropriate test cases. PR-URL: #12651 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Using `assert.AssertionError()` without the `new` keyword results in a non-intuitive error: ```js > assert.AssertionError({}) TypeError: Cannot assign to read only property 'name' of function 'function ok(value, message) { if (!value) fail(value, true, message, '==', assert.ok); }' at Function.AssertionError (assert.js:45:13) at repl:1:8 at realRunInThisContextScript (vm.js:22:35) at sigintHandlersWrap (vm.js:98:12) at ContextifyScript.Script.runInThisContext (vm.js:24:12) at REPLServer.defaultEval (repl.js:346:29) at bound (domain.js:280:14) at REPLServer.runBound [as eval] (domain.js:293:12) at REPLServer.onLine (repl.js:545:10) at emitOne (events.js:101:20) > ``` The `assert.AssertionError()` can only be used correctly with `new`, so this converts it into a proper ES6 class that will give an appropriate error message. This also associates the appropriate internal/errors code with all `assert.AssertionError` instances and updates the appropriate test cases. PR-URL: nodejs#12651 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Using
assert.AssertException()
without thenew
keyword results in a non-intuitive error:The
assert.AssertionError()
can only be used correctly withnew
, so this converts it into a proper ES6 class that will give an appropriate error message.This also associates the appropriate internal/errors code with all
assert.AssertionError
instances and updates the appropriate test cases.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
assert