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

esm: better error message for unsupported URL #31129

Closed
wants to merge 1 commit into from

Conversation

@Hakerh400
Copy link
Contributor

Hakerh400 commented Dec 29, 2019

The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

Fixes #31120

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines
@Hakerh400

This comment has been minimized.

Copy link
Contributor Author

Hakerh400 commented Dec 29, 2019

test/es-module/test-esm-dynamic-import.js

// TODO(jkrems): Right now this doesn't hit a protocol error because the
// module resolution step already rejects it. These arguably should be
// protocol errors.
expectMissingModuleError(import('node:fs'));
expectMissingModuleError(import('http://example.com/foo.js'));

This is the only test failing right now. The problem is that the loader converts the url to a file url and ignores the url scheme, producing a misleading error message (and it may probably load a wrong module). Should we update this test to check for ERR_UNSUPPORTED_ESM_URL_SCHEME, or should we delete this new error type and stick with the generic ERR_MODULE_NOT_FOUND?

Copy link
Member

devsnek left a comment

you can use parsed.scheme a few lines down.

@Hakerh400 Hakerh400 force-pushed the Hakerh400:esm-url branch from 39b2300 to 3e4eec1 Dec 29, 2019
doc/api/errors.md Outdated Show resolved Hide resolved
Copy link
Contributor

guybedford left a comment

Thanks for the PR, the approach looks great.

The test failures can be fixed by just changing the test expectations in https://github.com/nodejs/node/blob/master/test/es-module/test-esm-dynamic-import.js#L60. Note that the errors exactly align with a TODO comment @jkrems included previously.

The default ESM loader supports only file and data URLs.
This PR adds better error message for it.
@Hakerh400 Hakerh400 force-pushed the Hakerh400:esm-url branch from 3e4eec1 to b03912b Dec 29, 2019
@Trott
Trott approved these changes Dec 30, 2019
@nodejs-github-bot

This comment has been minimized.

@lpinca
lpinca approved these changes Dec 30, 2019
@Trott

This comment has been minimized.

Copy link
Member

Trott commented Dec 31, 2019

This is stalled on two issues in CI (nodejs/build#2116 and nodejs/build#2115) that will hopefully be resolved soon.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@BridgeAR

This comment has been minimized.

Copy link
Member

BridgeAR commented Jan 3, 2020

Landed in a25a628 🎉

@BridgeAR BridgeAR closed this Jan 3, 2020
BridgeAR added a commit to BridgeAR/node that referenced this pull request Jan 3, 2020
The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

PR-URL: nodejs#31129
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@Hakerh400 Hakerh400 deleted the Hakerh400:esm-url branch Jan 3, 2020
BridgeAR added a commit that referenced this pull request Jan 3, 2020
The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

PR-URL: #31129
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@BridgeAR BridgeAR mentioned this pull request Jan 7, 2020
MylesBorins added a commit that referenced this pull request Jan 12, 2020
The default ESM loader supports only file and data URLs.
This PR adds better error message for it.

PR-URL: #31129
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Guy Bedford <guybedford@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@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
Projects
None yet
8 participants
You can’t perform that action at this time.