Repository navigation
Eval and vm module with custom errors #7397
Description
Activity
- addedvmIssues and PRs related to the vm subsystem.Issues and PRs related to the vm subsystem.
on Jun 24, 2016 The reason is that the
vm.runInThisContext()'sdisplayErrorsoption istrueby default. Explicitly setting it tofalsewill get you:Eval - MyError MyError Good VM - Error Not MyError Bad VM - MyError MyError Bad VM - MyError Again MyErrorThe name
displayErrorsis a bit misleading, but what it actually does is decorate the exception message iftrue, which is what you're seeing (the filename is added and it points to the source line). When it'sfalse, the error is not decorated, so you just get the exception message itself. Originally when this option was added it did print the exception to stderr IIRC (hence the 'display' part of the name), but that behavior changed some time ago.- added a commit that references this issue
on Jun 24, 2016 PR: #7398
There is another question.
if (env->printed_error()) return; env->set_printed_error(true); uv_tty_reset_mode(); PrintErrorString("\n%s", arrow);Why print the error only once? The exception may occur repeatedly. If the output to stderr is allowed, I think it should be printed always rather than once.
Hm, maybe that made sense back in nodejs/node-v0.x-archive#7049, but I don’t see any real point right now either… @indutny you don’t happen to remember, do you?
- added a commit that references this issue
on Jul 27, 2026
I was playing around with dynamically running code and found a difference between standard JS eval and the vm module with custom error code. Here is a code snippet that can be run
and the output
It seems like custom errors in vm output to stdin(?) the first time they happen. They are even caught afterwards. This is not true for a standard Error in vm and both Errors work in JS Eval. I am not sure this is a expected behavior but it does not seem like it. Any feedback would be appreciated.
Thanks!