-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
repl: handle null thrown #14306
repl: handle null thrown #14306
Conversation
test/parallel/test-repl-sigint.js
Outdated
@@ -35,6 +35,7 @@ child.stdout.once('data', common.mustCall(() => { | |||
|
|||
child.on('close', function(code) { | |||
assert.strictEqual(code, 0); | |||
console.log(stdout); |
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.
whoops
lib/repl.js
Outdated
if (isError && e.stack) { | ||
top.outputStream.write(`${e.stack}\n`); | ||
} else { | ||
top.outputStream.write(`Error: ${e}\n`); |
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.
Well, things that are thrown aren't necessarily always errors. Maybe Thrown:
or just ${e}\n
?
(Also does this work with symbols?)
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.
@TimothyGu I preferred to make the smaller changed - for it to work with symbols we'd need to wrap it in String
(I can do that).
I can change the terminology from Error:
to Thrown:
I was hoping we could get a little bikeshedding on the 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.
Yeah well, this kinda goes back to #13784, which is still in limbo because of the lack of a good way to stringify an object.
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.
@TimothyGu yes, but I think String
is a good middle ground - I don't want it to be bulletproof - I want it to be useful for users.
lib/repl.js
Outdated
if (isError && e.stack) { | ||
top.outputStream.write(`${e.stack}\n`); | ||
} else { | ||
top.outputStream.write(`Error: ${e}\n`); |
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.
Yeah well, this kinda goes back to #13784, which is still in limbo because of the lack of a good way to stringify an object.
input: process.stdin | ||
}); | ||
|
||
replserver.emit('line', 'process.nextTick(() => { throw null; })'); |
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.
Is the process.nextTick
necessary?
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.
@TimothyGu yes, to reproduce the issue - without the nextTick it doesn't crash the REPL.
Previous behavior was to assume an error is a proper error in the repl module. A check was added to not terminate the process on thrown repl errors that are `null` or `undefined`. PR-URL: nodejs#14306 Fixes: nodejs#12373 Reviewed-By: Anna Henningsen <anna@addaleax.net>
3200c5a
to
4dfe7fd
Compare
@TimothyGu renamed "Error: " to "Thrown: " and handled thrown symbols. |
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.
internalUtil.decorateErrorStack(e); | ||
const isError = internalUtil.isError(e); |
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.
Why not process.binding('util').isNativeError
?
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.
@TimothyGu Not sure that's the behaviour I'd want - I'd like people to (optimally) be able to override Symbol.toStringTag
(or even the name) and take the "Error like" path if they really need to.
I don't feel strongly about this though. If you do - let me know and I'll change it.
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.
Sounds good to me.
replserver.emit('line', '.exit'); | ||
|
||
setTimeout(() => { | ||
console.log(text); |
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.
extraneous console.log()
output?
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.
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. I am curious why people aren't asking for all of the obnoxious scenarios from #12400 though :-D
I mean, we can still craft weird scenarios with |
Landed in 380e814. |
@TimothyGu note: you landed this without passing CI (last CI was failing due to changed error message). I've started a CI in https://ci.nodejs.org/job/node-test-pull-request/9246/console |
@benjamingr I didn't land this BTW, I just noticed it was landed w/o a "landed" comment. |
@TimothyGu I landed and immediately force reverted because of the CI (and posted in #node-dev) - currently waiting for CI to land this. |
@benjamingr Ah oops. Sorry, should've let you handle this (and checked IRC...) |
ARM fanned failure on |
Landed in 030a028 🎉 |
Previous behavior was to assume an error is a proper error in the repl module. A check was added to not terminate the process on thrown repl errors that are `null` or `undefined`. PR-URL: #14306 Fixes: #12373 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com
Previous behavior was to assume an error is a proper error in the repl module. A check was added to not terminate the process on thrown repl errors that are `null` or `undefined`. PR-URL: #14306 Fixes: #12373 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com
Previous behavior was to assume an error is a proper error in the repl module. A check was added to not terminate the process on thrown repl errors that are `null` or `undefined`. PR-URL: #14306 Fixes: #12373 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com
Should this be backported to |
ping @benjamingr |
1 similar comment
ping @benjamingr |
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
repl
Fixes #12373