errors: show url of unsupported attributes in the error message

PR-URL: https://github.com/nodejs/node/pull/58303
Fixes: https://github.com/nodejs/node/issues/56930
Reviewed-By: Jacob Smith <jacob@frende.me>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
This commit is contained in:
Aditi
2025-05-27 02:49:23 +05:30
committed by GitHub
parent a430ef50aa
commit 6f045771fa
2 changed files with 8 additions and 3 deletions

View File

@@ -1338,7 +1338,12 @@ E('ERR_IMPORT_ATTRIBUTE_MISSING',
E('ERR_IMPORT_ATTRIBUTE_TYPE_INCOMPATIBLE',
'Module "%s" is not of type "%s"', TypeError);
E('ERR_IMPORT_ATTRIBUTE_UNSUPPORTED',
'Import attribute "%s" with value "%s" is not supported', TypeError);
function error(attribute, value, url = undefined) {
if (url === undefined) {
return `Import attribute "${attribute}" with value "${value}" is not supported`;
}
return `Import attribute "${attribute}" with value "${value}" is not supported in ${url}`;
}, TypeError);
E('ERR_INCOMPATIBLE_OPTION_PAIR',
'Option "%s" cannot be used in combination with option "%s"', TypeError, HideStackFramesError);
E('ERR_INPUT_TYPE_NOT_ALLOWED', '--input-type can only be used with string ' +

View File

@@ -57,7 +57,7 @@ function validateAttributes(url, format,
const keys = ObjectKeys(importAttributes);
for (let i = 0; i < keys.length; i++) {
if (keys[i] !== 'type') {
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED(keys[i], importAttributes[keys[i]]);
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED(keys[i], importAttributes[keys[i]], url);
}
}
const validType = formatTypeMap[format];
@@ -102,7 +102,7 @@ function handleInvalidType(url, type) {
// `type` might not have been one of the types we understand.
if (!ArrayPrototypeIncludes(supportedTypeAttributes, type)) {
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED('type', type);
throw new ERR_IMPORT_ATTRIBUTE_UNSUPPORTED('type', type, url);
}
// `type` was the wrong value for this format.