Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
error handling feedback
  • Loading branch information
guybedford committed Jun 18, 2018
commit 233cf2af93b14dfd442a4d336381420e7c766982
4 changes: 2 additions & 2 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,8 +702,8 @@ E('ERR_INVALID_RETURN_VALUE', (input, name, value) => {
} else {
type = `type ${typeof value}`;
}
return `Expected ${input} to be returned from the ` +
`"${name}" function but got ${type}.`;
return `Expected ${input} to be returned from the "${name}"` +
` function but got ${type}.`;
}, TypeError);
E('ERR_INVALID_SYNC_FORK_INPUT',
'Asynchronous forks do not support Buffer, Uint8Array or string input: %s',
Expand Down
11 changes: 9 additions & 2 deletions lib/internal/modules/esm/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const {
ERR_INVALID_ARG_TYPE,
ERR_INVALID_RETURN_PROPERTY,
ERR_INVALID_RETURN_PROPERTY_STRING,
ERR_INVALID_RETURN_VALUE,
ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK,
ERR_UNKNOWN_MODULE_FORMAT
} = require('internal/errors').codes;
Expand Down Expand Up @@ -54,8 +55,14 @@ class Loader {
if (!isMain && typeof parentURL !== 'string')
throw new ERR_INVALID_ARG_TYPE('parentURL', 'string', parentURL);

const { url, format } =
await this._resolve(specifier, parentURL, defaultResolve);
const resolved = await this._resolve(specifier, parentURL, defaultResolve);

if (typeof resolved !== 'object')
throw new ERR_INVALID_RETURN_VALUE(
'object', 'loader resolve', resolved
);

const { url, format } = resolved;

if (typeof url !== 'string')
throw new ERR_INVALID_RETURN_PROPERTY(
Expand Down
15 changes: 7 additions & 8 deletions test/es-module/test-esm-loader-invalid-url.mjs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// Flags: --experimental-modules --loader ./test/fixtures/es-module-loaders/loader-invalid-url.mjs
/* eslint-disable node-core/required-modules */
import { expectsError, mustCall } from '../common';
import assert from 'assert';
import common from '../common';

import('../fixtures/es-modules/test-esm-ok.mjs')
.then(() => {
assert.fail();
}, (err) => {
assert.strictEqual(err.code, 'ERR_INVALID_RETURN_PROPERTY_STRING');
})
.then(common.mustCall());
.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.'
}))
.then(mustCall());
2 changes: 1 addition & 1 deletion test/fixtures/es-module-loaders/loader-invalid-url.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export async function resolve(specifier, parentModuleURL, defaultResolve) {
if (parentModuleURL && specifier !== 'assert') {
if (parentModuleURL && specifier === '../fixtures/es-modules/test-esm-ok.mjs') {
return {
url: specifier,
format: 'esm'
Expand Down