Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 1 addition & 3 deletions lib/internal/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -1001,9 +1001,7 @@ E('ERR_UNHANDLED_ERROR',
return `${msg} (${err})`;
}, Error);
E('ERR_UNKNOWN_ENCODING', 'Unknown encoding: %s', TypeError);

// This should probably be a `TypeError`.
E('ERR_UNKNOWN_FILE_EXTENSION', 'Unknown file extension: %s', Error);
E('ERR_UNKNOWN_FILE_EXTENSION', 'Unknown file extension: %s', TypeError);
E('ERR_UNKNOWN_MODULE_FORMAT', 'Unknown module format: %s', RangeError);
E('ERR_UNKNOWN_SIGNAL', 'Unknown signal: %s', TypeError);
E('ERR_UNKNOWN_STDIN_TYPE', 'Unknown stdin file type', Error);
Expand Down
17 changes: 0 additions & 17 deletions test/es-module/test-esm-loader-search.js

This file was deleted.

35 changes: 35 additions & 0 deletions test/es-module/test-esm-loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';
// Flags: --expose-internals

// This test ensures that resolve and search throw errors appropriately

const common = require('../common');
const tmpdir = require('../common/tmpdir');
const { join } = require('path');
const resolve = require('internal/modules/esm/default_resolve');
const { writeFileSync, unlinkSync } = require('fs');

const { search } = resolve;
const unsupported = join(
tmpdir.path,
'module-with-extension-that-is.unsupported');
tmpdir.refresh();
writeFileSync(unsupported, '');
common.expectsError(
() => resolve(unsupported, 'file://' + require.resolve(__filename)),
{
code: 'ERR_UNKNOWN_FILE_EXTENSION',
type: TypeError,
message: 'Unknown file extension: ' + unsupported
}
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you be so kind and post an example how a user could actually run into such an error without using any internals directly?

Copy link
Member Author

@davidmarkclements davidmarkclements Apr 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import foo from 'file://path/to/module.unsupported'

unlinkSync(unsupported);

common.expectsError(
() => search('target', undefined),
{
code: 'ERR_MISSING_MODULE',
type: Error,
message: 'Cannot find module target'
}
);