Skip to content
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

Merged
merged 1 commit into from
Nov 29, 2017

Conversation

bnoordhuis
Copy link
Member

@bnoordhuis bnoordhuis commented Nov 24, 2017

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. module Issues and PRs related to the module subsystem. tools Issues and PRs related to the tools directory. labels Nov 24, 2017
CHECK(!try_catch.Message().IsEmpty());
CHECK(!try_catch.Exception().IsEmpty());
AppendExceptionLine(env, try_catch.Exception(), try_catch.Message(),
ErrorHandlingMode::MODULE_ERROR);
Copy link
Member Author

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]>
@bnoordhuis bnoordhuis closed this Nov 29, 2017
@bnoordhuis bnoordhuis deleted the fix17277 branch November 29, 2017 11:29
@bnoordhuis bnoordhuis merged commit 597b3d1 into nodejs:master Nov 29, 2017
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
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]>
MylesBorins pushed a commit that referenced this pull request Dec 12, 2017
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]>
@MylesBorins MylesBorins mentioned this pull request Dec 12, 2017
@gibfahn
Copy link
Member

gibfahn commented Dec 19, 2017

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

targos added a commit to targos/node that referenced this pull request Dec 20, 2017
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
targos added a commit to targos/node that referenced this pull request Dec 24, 2017
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]>
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
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]>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
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]>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
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]>
@jasnell
Copy link
Member

jasnell commented Aug 17, 2018

Not convinced that this needs to be backported to 8.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. module Issues and PRs related to the module subsystem. tools Issues and PRs related to the tools directory.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants