Skip to content

repl: handle null thrown #14306

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
wants to merge 2 commits into from

Conversation

benjamingr
Copy link
Member

@benjamingr benjamingr commented Jul 16, 2017

  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

repl

Fixes #12373

@nodejs-github-bot nodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Jul 16, 2017
@@ -35,6 +35,7 @@ child.stdout.once('data', common.mustCall(() => {

child.on('close', function(code) {
assert.strictEqual(code, 0);
console.log(stdout);
Copy link
Member Author

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`);
Copy link
Member

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?)

Copy link
Member Author

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.

Copy link
Member

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.

Copy link
Member Author

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`);
Copy link
Member

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; })');
Copy link
Member

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?

Copy link
Member Author

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>
@benjamingr benjamingr force-pushed the repl-handle-null-thrown branch from 3200c5a to 4dfe7fd Compare July 17, 2017 08:18
@benjamingr
Copy link
Member Author

@TimothyGu renamed "Error: " to "Thrown: " and handled thrown symbols.

Copy link
Member

@TimothyGu TimothyGu left a 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);
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member

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);
Copy link
Member

Choose a reason for hiding this comment

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

extraneous console.log() output?

Copy link
Contributor

@Fishrock123 Fishrock123 left a comment

Choose a reason for hiding this comment

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

Copy link
Contributor

@cjihrig cjihrig left a 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

@TimothyGu
Copy link
Member

I mean, we can still craft weird scenarios with @@toStringTag, @@toPrimitive, valueOf, toString, stack, Proxys, etc. I know I've fallen into the traps of bikeshedding before (sorry @cjihrig), but this seems like as KISS of a threshold as any. And I guess the user deserves to get some weird error if they does one or more of those things.

@TimothyGu
Copy link
Member

Landed in 380e814.

@TimothyGu TimothyGu closed this Jul 19, 2017
@benjamingr
Copy link
Member Author

@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

@TimothyGu
Copy link
Member

@benjamingr I didn't land this BTW, I just noticed it was landed w/o a "landed" comment.

@benjamingr
Copy link
Member Author

@TimothyGu I landed and immediately force reverted because of the CI (and posted in #node-dev) - currently waiting for CI to land this.

@benjamingr benjamingr reopened this Jul 19, 2017
@TimothyGu
Copy link
Member

@benjamingr Ah oops. Sorry, should've let you handle this (and checked IRC...)

@benjamingr
Copy link
Member Author

ARM fanned failure on inspector/test-inspector-port-cluster unrelated.

@benjamingr
Copy link
Member Author

Landed in 030a028 🎉

@benjamingr benjamingr closed this Jul 19, 2017
benjamingr pushed a commit that referenced this pull request Jul 19, 2017
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
addaleax pushed a commit that referenced this pull request Jul 22, 2017
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
Fishrock123 pushed a commit that referenced this pull request Jul 24, 2017
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
@addaleax addaleax mentioned this pull request Jul 24, 2017
@addaleax addaleax mentioned this pull request Aug 2, 2017
@MylesBorins
Copy link
Contributor

Should this be backported to v6.x-staging? If yes please follow the guide and raise a backport PR, if no let me know or add the dont-land-on label.

@MylesBorins
Copy link
Contributor

ping @benjamingr

1 similar comment
@MylesBorins
Copy link
Contributor

ping @benjamingr

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants