Skip to content

Commit 8c60167

Browse files
committed
errors: show url of unsupported attributes in the error message
1 parent acb3d92 commit 8c60167

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

lib/internal/errors.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1338,7 +1338,11 @@ 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+
return `Import attribute "${attribute}" with value "${value}" is not supported in ${url}`;
1345+
}, TypeError);
13421346
E('ERR_INCOMPATIBLE_OPTION_PAIR',
13431347
'Option "%s" cannot be used in combination with option "%s"', TypeError, HideStackFramesError);
13441348
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)