Skip to content

Commit

Permalink
lib: add parent to ERR_UNKNOWN_FILE_EXTENSION
Browse files Browse the repository at this point in the history
- default_resolve updated to pass parentURL into error
- ERR_UNKNOWN_FILE_EXTENSION updated to include parentURL
- test added to check for import message in error

PR-URL: #30728
Fixes: #30721
Reviewed-By: Guy Bedford <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
  • Loading branch information
qualitymanifest authored and targos committed Dec 9, 2019
1 parent d9d6475 commit 2c439bb
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1228,7 +1228,9 @@ E('ERR_UNHANDLED_ERROR',
E('ERR_UNKNOWN_BUILTIN_MODULE', 'No such built-in module: %s', Error);
E('ERR_UNKNOWN_CREDENTIAL', '%s identifier does not exist: %s', Error);
E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s', TypeError);
E('ERR_UNKNOWN_FILE_EXTENSION', 'Unknown file extension: %s', TypeError);
E('ERR_UNKNOWN_FILE_EXTENSION',
'Unknown file extension "%s" for %s imported from %s',
TypeError);
E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError);
E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError);

Expand Down
5 changes: 4 additions & 1 deletion lib/internal/modules/esm/default_resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ function resolve(specifier, parentURL) {
'ExperimentalWarning');
format = legacyExtensionFormatMap[ext];
} else {
throw new ERR_UNKNOWN_FILE_EXTENSION(fileURLToPath(url));
throw new ERR_UNKNOWN_FILE_EXTENSION(
ext,
fileURLToPath(url),
fileURLToPath(parentURL));
}
}
return { url: `${url}`, format };
Expand Down
2 changes: 2 additions & 0 deletions test/es-module/test-esm-invalid-extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ const { spawnSync } = require('child_process');
const fixture = fixtures.path('/es-modules/import-invalid-ext.mjs');
const child = spawnSync(process.execPath, [fixture]);
const errMsg = 'TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension';
const importMsg = `imported from ${fixture}`;

assert.strictEqual(child.status, 1);
assert.strictEqual(child.signal, null);
assert.strictEqual(child.stdout.toString().trim(), '');
assert(child.stderr.toString().includes(errMsg));
assert(child.stderr.toString().includes(importMsg));

0 comments on commit 2c439bb

Please sign in to comment.