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
Member

@MylesBorins MylesBorins commented May 27, 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

@nodejs-github-bot nodejs-github-bot added the repl label May 27, 2020
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented May 27, 2020

@MylesBorins MylesBorins added the esm label May 27, 2020
@MylesBorins MylesBorins requested a review from BridgeAR May 27, 2020
Copy link
Member

@BridgeAR BridgeAR left a comment

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
Member Author

@MylesBorins MylesBorins commented Jul 20, 2020

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
Member Author

@MylesBorins MylesBorins Jul 20, 2020

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

@BridgeAR BridgeAR Jul 21, 2020

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
Member Author

@MylesBorins MylesBorins Jul 22, 2020

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

@BridgeAR BridgeAR commented Jul 21, 2020

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
Member Author

@MylesBorins MylesBorins commented Jul 21, 2020

@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
Contributor

@nodejs-github-bot nodejs-github-bot commented Jul 23, 2020

@MylesBorins MylesBorins added the author ready label Jul 25, 2020
@MylesBorins
Copy link
Member Author

@MylesBorins MylesBorins commented Jul 30, 2020

hey @BridgeAR are you ok with this landing?

@MylesBorins
Copy link
Member Author

@MylesBorins MylesBorins commented Aug 3, 2020

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

MylesBorins added a commit that referenced this issue 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
Member Author

@MylesBorins MylesBorins commented Aug 5, 2020

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

@Trott Trott Aug 6, 2020

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

@Trott Trott Aug 6, 2020

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

@Trott Trott Aug 6, 2020

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
Member Author

@MylesBorins MylesBorins Aug 6, 2020

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 added a commit that referenced this issue 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 added a commit that referenced this issue 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 issue 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 issue 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 esm repl
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

7 participants