-
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
SyntaxError objects should contain information about where the syntax error happened #3411
Comments
That |
@tflanagan Yes I expected that to be the case, but it still ideally shouldn't appear in the exception. |
Also related to issue #2762 |
+1 for fixing this. I spent half day trying to fix things in a wrong file... |
Currently, when a file with a syntax error is imported in the REPL, no information is provided on the error's location. This commit adds the error's location to the stack trace. Refs: nodejs#2762 Refs: nodejs#3411 Refs: nodejs#3784 PR-URL: nodejs#4013 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Currently, when a file with a syntax error is imported in the REPL, no information is provided on the error's location. This commit adds the error's location to the stack trace. Refs: nodejs#2762 Refs: nodejs#3411 Refs: nodejs#3784 PR-URL: nodejs#4013 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Currently, when a file with a syntax error is imported in the REPL, no information is provided on the error's location. This commit adds the error's location to the stack trace. Refs: nodejs#2762 Refs: nodejs#3411 Refs: nodejs#3784 PR-URL: nodejs#4013 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@fresheneesz This should be fixed by #4874. Can you confirm this issue is fixed on master? |
This was fixed in v6, and the module wrapper was documented. Closing. |
I don't understand why this is closed.. This is still an issue in Node v8.x |
This was closed because #4874 landed as 5700352. That commit has been in every Node release since 6.0.0 (including all 8.x releases). If you're still seeing this issue could you provide more details? Ideally let us know why 5700352 didn't fix your problem. |
Consider these files:
test.js:
testmodule.js:
In this case, the result is the following text:
Notice that it doesn't give you any information about what module that unexpected token is in nor what line in the module that unexpected token was found at. This makes it pretty hard to debug in cases where you're requiring a module somewhere other than at the very top of your source.
You can usually infer the module its in by looking at the line in test.js that it indicates, but if you have more than one module required in the same line, that won't tell you which one.
If you don't catch the SyntaxError, you get the following additional info:
This is super helpful (although it incorrectly contains some boilerplate - the
);
that doesn't actually exist in the file), and should be contained in the error'smessage
andstack
properties. At very least, the error object should contain those two pieces of information somewhere.The text was updated successfully, but these errors were encountered: