diff --git a/doc/api/errors.md b/doc/api/errors.md index 487d558ec3f369..4d871c0c1c188e 100644 --- a/doc/api/errors.md +++ b/doc/api/errors.md @@ -1207,18 +1207,20 @@ is not supported. ### ERR_INVALID_RETURN_PROPERTY -Thrown in case a function option does not return an expected property type. +Thrown in case a function option does not provide a valid value for one of its +returned object properties on execution. - -### ERR_INVALID_RETURN_PROPERTY_STRING + +### ERR_INVALID_RETURN_PROPERTY_VALUE -Thrown in case a function option does not return an expected string property -type. +Thrown in case a function option does not provide an expected value +type for one of its returned object properties on execution. ### ERR_INVALID_RETURN_VALUE -Thrown in case a function option does not return an expected value on execution. +Thrown in case a function option does not return an expected value +type on execution. For example when a function is expected to return a promise. diff --git a/lib/internal/errors.js b/lib/internal/errors.js index ac87965421ad1a..507a42962c45b5 100644 --- a/lib/internal/errors.js +++ b/lib/internal/errors.js @@ -682,18 +682,18 @@ E('ERR_INVALID_PROTOCOL', E('ERR_INVALID_REPL_EVAL_CONFIG', 'Cannot specify both "breakEvalOnSigint" and "eval" for REPL', TypeError); E('ERR_INVALID_RETURN_PROPERTY', (input, name, prop, value) => { + return `Expected a valid ${input} to be returned for the "${prop}" from the` + + ` "${name}" function but got ${value}.`; +}, TypeError); +E('ERR_INVALID_RETURN_PROPERTY_VALUE', (input, name, prop, value) => { let type; if (value && value.constructor && value.constructor.name) { type = `instance of ${value.constructor.name}`; } else { type = `type ${typeof value}`; } - return `Expected ${input} to be returned for the ${prop} from the ` + - `"${name}" function but got ${type}.`; -}, TypeError); -E('ERR_INVALID_RETURN_PROPERTY_STRING', (input, name, prop, value) => { - return `Expected a valid ${input} to be returned for the ${prop} from the ` + - `"${name}" function but got ${value}.`; + return `Expected ${input} to be returned for the "${prop}" from the` + + ` "${name}" function but got ${type}.`; }, TypeError); E('ERR_INVALID_RETURN_VALUE', (input, name, value) => { let type; diff --git a/lib/internal/modules/esm/loader.js b/lib/internal/modules/esm/loader.js index a88b77f360df3e..17a9686f736060 100644 --- a/lib/internal/modules/esm/loader.js +++ b/lib/internal/modules/esm/loader.js @@ -3,7 +3,7 @@ const { ERR_INVALID_ARG_TYPE, ERR_INVALID_RETURN_PROPERTY, - ERR_INVALID_RETURN_PROPERTY_STRING, + ERR_INVALID_RETURN_PROPERTY_VALUE, ERR_INVALID_RETURN_VALUE, ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK, ERR_UNKNOWN_MODULE_FORMAT @@ -65,13 +65,13 @@ class Loader { const { url, format } = resolved; if (typeof url !== 'string') - throw new ERR_INVALID_RETURN_PROPERTY( + throw new ERR_INVALID_RETURN_PROPERTY_VALUE( 'string', 'loader resolve', 'url', url ); if (typeof format !== 'string') - throw new ERR_INVALID_RETURN_PROPERTY_STRING( - 'string', 'loader resolve', 'format', format + throw new ERR_INVALID_RETURN_PROPERTY( + 'module format', 'loader resolve', 'format', format ); if (format === 'builtin') @@ -81,14 +81,14 @@ class Loader { try { new URL(url); } catch (e) { - throw new ERR_INVALID_RETURN_PROPERTY_STRING( + throw new ERR_INVALID_RETURN_PROPERTY( 'url', 'loader resolve', 'url', url ); } } if (format !== 'dynamic' && !url.startsWith('file:')) - throw new ERR_INVALID_RETURN_PROPERTY_STRING( + throw new ERR_INVALID_RETURN_PROPERTY( 'file: url', 'loader resolve', 'url', url ); diff --git a/test/es-module/test-esm-loader-invalid-url.mjs b/test/es-module/test-esm-loader-invalid-url.mjs index 4ace7b183134a8..43971a2e6e3b71 100644 --- a/test/es-module/test-esm-loader-invalid-url.mjs +++ b/test/es-module/test-esm-loader-invalid-url.mjs @@ -4,8 +4,9 @@ import assert from 'assert'; import('../fixtures/es-modules/test-esm-ok.mjs') .then(assert.fail, expectsError({ - code: 'ERR_INVALID_RETURN_PROPERTY_STRING', - message: 'Expected a valid url to be returned for the url from the "loader ' + - 'resolve" function but got ../fixtures/es-modules/test-esm-ok.mjs.' + code: 'ERR_INVALID_RETURN_PROPERTY', + message: 'Expected a valid url to be returned for the "url" from the ' + + '"loader resolve" function but got ' + + '../fixtures/es-modules/test-esm-ok.mjs.' })) .then(mustCall());