◐ Shell
clean mode source ↗

errors: show url of unsupported attributes in the error message · nodejs/node@252acc1

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 ' +

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.