-
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
displayErrors option of the vm module seems not to work well #4835
Comments
I had a look and I can confirm what you're describing. What happens is this:
Example: var vm = require('vm');
var util = require('internal/util'); // requires --expose_internals
try {
new vm.Script('?', {filename: 'x.js', displayErrors: true});
} catch (e) {
console.error('arrowMessage:', util.getHiddenValue(e, 'node:arrowMessage'));
} Which prints:
If you let the exception bubble up to node's top-level exception handler, it will include the arrowMessage string in the output. With that in mind:
It's as correct as it can be given the circumstances but it's at odds with the documentation. We could either restore the old behavior where node prints the message immediately on syntax error or we could update the documentation. If we update the documentation, there probably needs to be an official way to get the hidden property, which is awkward.
Nothing official at the moment, no, except for letting the exception bubble up. (EDIT: Which doesn't work for promises, of course.) /cc @nodejs/documentation @cjihrig |
Why? |
The exception won't bubble up all the way, at least not by default. You could add a |
Well, if you have I get your point though - thanks. |
My guess is that this behavior goes back to f1de13b, which fixes nodejs/node-v0.x-archive#6920. @bnoordhuis I'm happy to work on this if we decide how we want to fix it. |
@bnoordhuis Thank you for your answer. I see the point. I will try to use |
@cjihrig The best I can come up with is to intercept the SyntaxError and add the extra information to the |
The vm module's displayErrors option attaches error arrow messages as a hidden property. Later, core JavaScript code can optionally decorate the error stack with the arrow message. However, when user code catches an error, it has no way to access the arrow message. This commit changes the behavior of displayErrors to mean "decorate the error stack if an error occurs." Fixes: nodejs#4835
The vm module's displayErrors option attaches error arrow messages as a hidden property. Later, core JavaScript code can optionally decorate the error stack with the arrow message. However, when user code catches an error, it has no way to access the arrow message. This commit changes the behavior of displayErrors to mean "decorate the error stack if an error occurs." Fixes: nodejs#4835 PR-URL: nodejs#4874 Reviewed-By: Ben Noordhuis <[email protected]>
The vm module's displayErrors option attaches error arrow messages as a hidden property. Later, core JavaScript code can optionally decorate the error stack with the arrow message. However, when user code catches an error, it has no way to access the arrow message. This commit changes the behavior of displayErrors to mean "decorate the error stack if an error occurs." Fixes: nodejs#4835 PR-URL: nodejs#4874 Reviewed-By: Ben Noordhuis <[email protected]>
I'm stuck for the behavior of the
displayErrors
option of the vm module.First I wrote the code like below and this works well.
When
displayErrors
are set totrue
, however, the behavior seems to be not consistent with the document "print any errors to stderr before throwing an exception" since this code does not output anything to stderr.Next, I tried to catch the error and get the information where the error has occurred but I couldn't.
I also re-threw the error and found that the information about the script is discarded when the error is re-thrown if
displayErrors: false
, while thedisplayErrors: true
version retains it.The problem is more serious when combined with
Promise
.This code actually does not print anything since the error is swallowed by the Promise, and I have no idea to know where the error occurred in the script.
Note that all the codes throw syntax errors, but the results are almost same for throwing runtime errors.
Taken together, it seems that
displayErrors: true
does only make the error retain the information where it occurred and does not letnew vm.Script
(andrunInContext
or something) print anything.In addition, there seems to be no way to know where the error occurred if it is in Promise.
Here I have two questions.
displayErrors: true
is correct?The version of Node.js is v5.5.0.
Thanks.
The text was updated successfully, but these errors were encountered: