-
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
module: print nicer error message on syntax error #17281
Conversation
CHECK(!try_catch.Message().IsEmpty()); | ||
CHECK(!try_catch.Exception().IsEmpty()); | ||
AppendExceptionLine(env, try_catch.Exception(), try_catch.Message(), | ||
ErrorHandlingMode::MODULE_ERROR); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could just use FATAL_ERROR
here and undo the change to node_internals.h but I figured it might be nice to distinguish between "normal" fatal errors and ones from the esm module loader.
Include the offending line in the output and underline the bad token. Before this commit, it printed "SyntaxError: Unexpected reserved word" without indicating where the syntax error is. Now it prints the line and underlines the offending token, like it does for syntax errors in CJS scripts. Minor changes are made to the test runner in order to support `*.mjs` files in test/message. Fixes: nodejs#17277 PR-URL: nodejs#17281 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Include the offending line in the output and underline the bad token. Before this commit, it printed "SyntaxError: Unexpected reserved word" without indicating where the syntax error is. Now it prints the line and underlines the offending token, like it does for syntax errors in CJS scripts. Minor changes are made to the test runner in order to support `*.mjs` files in test/message. Fixes: #17277 PR-URL: #17281 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Include the offending line in the output and underline the bad token. Before this commit, it printed "SyntaxError: Unexpected reserved word" without indicating where the syntax error is. Now it prints the line and underlines the offending token, like it does for syntax errors in CJS scripts. Minor changes are made to the test runner in order to support `*.mjs` files in test/message. Fixes: #17277 PR-URL: #17281 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
Should this be backported to 8.x? If so could someone raise a backport PR, as this fails with: [01:39|% 98|+ 2017|- 0]: release esm_display_syntax_error.mjs match failed
line=5
expect=^\ \ \ \ at\ loaders\.set\ \(internal\/loader\/ModuleRequest\.js\:.*\:.*\)$
actual= at ModuleJob.loaders.set [as moduleProvider] (internal/loader/ModuleRequest.js:33:13)
=== release esm_display_syntax_error.mjs ===
Path: message/esm_display_syntax_error.mjs
(node:64175) ExperimentalWarning: The ESM module loader is experimental.
file:///build/gib/node/test/message/esm_display_syntax_error.mjs:3
await async () => 0;
^^^^^
SyntaxError: Unexpected reserved word
at ModuleJob.loaders.set [as moduleProvider] (internal/loader/ModuleRequest.js:33:13)
at <anonymous>
Command: out/Release/node --experimental-modules /build/gib/node/test/message/esm_display_syntax_error.mjs
[01:39|% 98|+ 2017|- 1]: release esm_display_syntax_error_module.mjs match failed
line=5
expect=^\ \ \ \ at\ loaders\.set\ \(internal\/loader\/ModuleRequest\.js\:.*\:.*\)$
actual= at ModuleJob.loaders.set [as moduleProvider] (internal/loader/ModuleRequest.js:33:13)
=== release esm_display_syntax_error_module.mjs ===
Path: message/esm_display_syntax_error_module.mjs
(node:64185) ExperimentalWarning: The ESM module loader is experimental.
file:///build/gib/node/test/fixtures/es-module-loaders/syntax-error.mjs:2
await async () => 0;
^^^^^
SyntaxError: Unexpected reserved word
at ModuleJob.loaders.set [as moduleProvider] (internal/loader/ModuleRequest.js:33:13)
at <anonymous>
Command: out/Release/node --experimental-modules /build/gib/node/test/message/esm_display_syntax_error_module.mjs |
Use the same approach as a previous PR to include the offending line in the output and underline imports of inexistent exports. Fixes: nodejs#17785 Refs: nodejs#17281
Use the same approach as a previous PR to include the offending line in the output and underline imports of inexistent exports. PR-URL: nodejs#17786 Fixes: nodejs#17785 Refs: nodejs#17281 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: James M Snell <[email protected]>
Use the same approach as a previous PR to include the offending line in the output and underline imports of inexistent exports. PR-URL: #17786 Fixes: #17785 Refs: #17281 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: James M Snell <[email protected]>
Use the same approach as a previous PR to include the offending line in the output and underline imports of inexistent exports. PR-URL: #17786 Fixes: #17785 Refs: #17281 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: James M Snell <[email protected]>
Use the same approach as a previous PR to include the offending line in the output and underline imports of inexistent exports. PR-URL: #17786 Fixes: #17785 Refs: #17281 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Guy Bedford <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]> Reviewed-By: James M Snell <[email protected]>
Not convinced that this needs to be backported to 8.x |
Fixes: #17277
CI: https://ci.nodejs.org/job/node-test-pull-request/11682/