Skip to content

Commit 252acc1

Browse files
Aditi-1400targos
authored andcommitted
errors: show url of unsupported attributes in the error message
PR-URL: #58303 Fixes: #56930 Reviewed-By: Jacob Smith <jacob@frende.me> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 08615b1 commit 252acc1

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/internal/errors.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,12 @@ E('ERR_IMPORT_ATTRIBUTE_MISSING',
13381338
E('ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE',
13391339
'Module "%s" is not of type "%s"', TypeError);
13401340
E('ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
1341-
'Import attribute "%s" with value "%s" is not supported', TypeError);
1341+
function error(attribute, value, url = undefined) {
1342+
if (url === undefined) {
1343+
return `Import attribute "${attribute}" with value "${value}" is not supported`;
1344+
}
1345+
return `Import attribute "${attribute}" with value "${value}" is not supported in ${url}`;
1346+
}, TypeError);
13421347
E('ERR_INCOMPATIBLE_OPTION_PAIR',
13431348
'Option "%s" cannot be used in combination with option "%s"', TypeError, HideStackFramesError);
13441349
E('ERR_INPUT_TYPE_NOT_ALLOWED', '--input-type can only be used with string ' +

lib/internal/modules/esm/assert.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ function validateAttributes(url, format,
5757
const keys = ObjectKeys(importAttributes);
5858
for (let i = 0; i < keys.length; i++) {
5959
if (keys[i] !== 'type') {
60-
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED(keys[i], importAttributes[keys[i]]);
60+
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED(keys[i], importAttributes[keys[i]], url);
6161
}
6262
}
6363
const validType = formatTypeMap[format];
@@ -102,7 +102,7 @@ function handleInvalidType(url, type) {
102102

103103
// `type` might not have been one of the types we understand.
104104
if (!ArrayPrototypeIncludes(supportedTypeAttributes, type)) {
105-
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED('type', type);
105+
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED('type', type, url);
106106
}
107107

108108
// `type` was the wrong value for this format.

0 commit comments

Comments
 (0)