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

repl: improve static import error message in repl #33588

Closed
wants to merge 1 commit into from

Conversation

MylesBorins
Copy link
Contributor

Currently the error is rather ambiguous and does not inform folks that
static import is not supported in the repl. This overrides the default
error message with one that is more informative.

Closes: #33576

@nodejs-github-bot nodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label May 27, 2020
@nodejs-github-bot
Copy link
Collaborator

@MylesBorins MylesBorins added the esm Issues and PRs related to the ECMAScript Modules implementation. label May 27, 2020
@MylesBorins MylesBorins requested a review from BridgeAR May 27, 2020 16:32
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic should probably be moved here:

// Remove stack trace.

lib/repl.js Outdated Show resolved Hide resolved
lib/repl.js Outdated Show resolved Hide resolved
lib/repl.js Outdated Show resolved Hide resolved
@MylesBorins
Copy link
Contributor Author

I've updated PTAL

@BridgeAR I don't think we need to check the length on this. If someone is explicitly messing with the stack size I'm pretty happy that this feature might fail for them. Thoughts?

lib/repl.js Outdated
e.message = 'Cannot use import statement inside the Node.js repl, ' +
'please use dynamic import instead';
const splitStack = StringPrototypeSplit(e.stack, '\n');
splitStack[4] = `SyntaxError: ${e.message}`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could alternative find which item in the array starts with SyntaxError rather than by default using the 5th item

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds better to me. There is in fact similar code to determine that line below. It'll only be triggered in case there's no uncaughtException listener though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use regex PTAL

@BridgeAR
Copy link
Member

Is it not possible to just fix static import? That would be most user friendly and I would rather have that. I guess it might be tricky to implement it though?

@MylesBorins
Copy link
Contributor Author

@BridgeAR AFAIK there is no way to implement static import in the REPL. I could be wrong, but in lieu of a solution to that this seems like the next best thing.

Currently the error is rather ambiguous and does not inform folks that
static import is not supported in the repl. This overrides the default
error message with one that is more informative.

Closes: nodejs#33576
@nodejs-github-bot
Copy link
Collaborator

@MylesBorins MylesBorins added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jul 25, 2020
@MylesBorins
Copy link
Contributor Author

hey @BridgeAR are you ok with this landing?

@MylesBorins
Copy link
Contributor Author

Pinging @BridgeAR one more time. I'll land in 48 hours if I don't hear anything.

MylesBorins added a commit that referenced this pull request Aug 5, 2020
Currently the error is rather ambiguous and does not inform folks that
static import is not supported in the repl. This overrides the default
error message with one that is more informative.

Closes: #33576

PR-URL: #33588
Fixes: #33576
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins
Copy link
Contributor Author

Landed in 861a54c

@MylesBorins MylesBorins closed this Aug 5, 2020
@@ -805,6 +805,16 @@ const tcpTests = [
{
send: `require(${JSON.stringify(moduleFilename)}).number`,
expect: '42'
},
{
send: 'import comeOn from \'fhqwhgads\'',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
send: 'import comeOn from \'fhqwhgads\'',
send: 'import everybody from \'the limit\'',

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought...

Suggested change
send: 'import comeOn from \'fhqwhgads\'',
send: 'import theLimit from \'everybody\'',

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long descriptive names are preferable.

Suggested change
send: 'import comeOn from \'fhqwhgads\'',
send: 'import comeOn from \'fhqwhgadshgnsdhjsdbkhsdabkfabkveybvf\'',

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOLOLOL

guess this will need to come in a followup

codebytere pushed a commit that referenced this pull request Aug 6, 2020
Currently the error is rather ambiguous and does not inform folks that
static import is not supported in the repl. This overrides the default
error message with one that is more informative.

Closes: #33576

PR-URL: #33588
Fixes: #33576
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@codebytere codebytere mentioned this pull request Aug 10, 2020
codebytere pushed a commit that referenced this pull request Aug 11, 2020
Currently the error is rather ambiguous and does not inform folks that
static import is not supported in the repl. This overrides the default
error message with one that is more informative.

Closes: #33576

PR-URL: #33588
Fixes: #33576
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins added a commit that referenced this pull request Nov 3, 2020
Currently the error is rather ambiguous and does not inform folks that
static import is not supported in the repl. This overrides the default
error message with one that is more informative.

Closes: #33576

PR-URL: #33588
Fixes: #33576
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins MylesBorins mentioned this pull request Nov 3, 2020
MylesBorins added a commit that referenced this pull request Nov 16, 2020
Currently the error is rather ambiguous and does not inform folks that
static import is not supported in the repl. This overrides the default
error message with one that is more informative.

Closes: #33576

PR-URL: #33588
Fixes: #33576
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. esm Issues and PRs related to the ECMAScript Modules implementation. repl Issues and PRs related to the REPL subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Better error message for using static import in repl
7 participants