-
Notifications
You must be signed in to change notification settings - Fork 7.3k
VM.runInThisContext filename param not in stack trace, docs say it should be #3452
Comments
This same symptom occurs with vm.runInContext vm.runInNewContext and vm.createScript as well. |
Confirmed. It's interesting that we get the correct output from syntax errors in modules, though, since that's exactly what we do in node to load them. Very curious indeed. |
Note: if something in the parsed module throws, then I'm seeing the correct output. It looks like only SyntaxErrors that are handled improperly. |
So, I started looking through node_script.cc a there's an undocumented boolean parameter display_errors that you can pass to these methods that will cause it to attempt to print more info about the syntax error to stderr. However, it doesn't work right either, in that it assumes the script is a wrapped script and it needs to back out the 62 character function preamble that wraps module scripts (but not these) so the line/col numbers are all screwed up. It does get you the file name printed to stderr though. Script with added
Output:
Really, I think the approach taken in node_script.cc probably just needs to be revisited, it appears it's author thought so as well based on the comments.
I'm not much of a C++ developer, but maybe I'll take a whack at making a patch for fixing this error handling, if you're amenable to it. |
… V8 rethrow being broken.
+1 for this to be fixed |
I've submitted a patch for the V8 folks which fixes the |
I published an integration branch containing the V8 fix and removing the https://github.com/apaprocki/node/tree/issue-3452 With the fix, this test:
produces the correct exception and stack:
|
@apaprocki I've tried out your branch. If I understand correctly, it allows you to remove the hacky call to DisplayExceptionLine in node_script.cc... but it doesn't actually make the syntax error's real location available to JS code that is calling vm.runInWhateverContext, right? ie, there's still no way to do:
right? (Not to say that your patch isn't a definite improvement, just wondering if the above is possible.) |
@glasser Do you have an example that isn't working the way you expect? In my example in the update before yours, if I modify the second |
@apaprocki I agree that if you do
then the stack correctly points to the inner (Again, this is in no way an objection to a patch which improves the situation. Just wondering if we could improve it further while we're at it :) ) |
V8 does not set the filename and line number as properties on the The V8 team has indicated that they are only exposing the These two bugs are requesting that it be fixed: As soon as some solution is found there at the V8 level, I think you will get what you're looking for. |
+1 Would love to have this fixed |
Closing, works in master:
That's about as good as it gets. |
@bnoordhuis That's not actually what is being asked for. The problem is that if you catch that error instead of letting it get to the built-in top level, there's nothing in As far as I can tell this is a V8 issue. See eg https://code.google.com/p/v8/issues/detail?id=1281 and https://code.google.com/p/v8/issues/detail?id=1914 |
That's what I mean with 'as good as it gets'. Node reports the proper file name at the top. The stack trace is V8 territory, not something we can fix in node. |
From the vm docs:
but when you run a script that has invalid js that causes a syntax error...
The output has no filename in it.
Here's sample output:
Notice that the file name appears nowhere in the stack trace or the message. This makes it very difficult to track down errors in scripts that you are trying to run with vm, as the stack trace points you to the wrong place. Ideally, there'd be another element atop the stack trace with the line numbers of the script evaluated by vm.
Here's the output that would be ideal:
The text was updated successfully, but these errors were encountered: