Skip to content

Commit 5d542df

Browse files
committed
Revert "Include the underlying exception in ESM import exceptions"
This reverts commit 2dcd739. The cause property of Error objects was added in >=16.9.0, and only works reliably in >=16.14.0. We still support older versions. To be reintroduced in 5.0.
1 parent 2dcd739 commit 5d542df

File tree

2 files changed

+5
-14
lines changed

2 files changed

+5
-14
lines changed

lib/loader.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,7 @@ function fixupImportException(e, importedPath) {
138138
|| e.stack.match(anyWindowsPathFirstLineRegex)) {
139139
return e;
140140
} else {
141-
return new Error(
142-
`While loading ${importedPath}: ${e.constructor.name}: ${e.message}`,
143-
{cause: e}
144-
);
141+
return new Error(`While loading ${importedPath}: ${e.constructor.name}: ${e.message}`);
145142
}
146143
}
147144

spec/loader_spec.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('loader', function() {
2020
esModuleSharedExamples('js', true);
2121
});
2222

23-
describe('When the extension is not supported by import()', function() {
23+
describe('When the extnesion is not supported by import()', function() {
2424
it('falls back to require()', async function() {
2525
const error = new TypeError();
2626
error.code = 'ERR_UNKNOWN_FILE_EXTENSION';
@@ -155,15 +155,9 @@ function esModuleSharedExamples(extension, alwaysImport) {
155155
const underlyingError = new SyntaxError('some details but no filename, not even in the stack trace');
156156
const loader = new Loader({importShim: () => Promise.reject(underlyingError)});
157157

158-
try {
159-
await loader.load(`foo.${extension}`, alwaysImport);
160-
fail('Expected loader to throw but it did not');
161-
} catch (thrown) {
162-
expect(thrown.message).toEqual(
163-
`While loading foo.${extension}: SyntaxError: some details but no filename, not even in the stack trace`
164-
);
165-
expect(thrown.cause).toBe(underlyingError);
166-
}
158+
await expectAsync(loader.load(`foo.${extension}`, alwaysImport)).toBeRejectedWithError(
159+
`While loading foo.${extension}: SyntaxError: some details but no filename, not even in the stack trace`
160+
);
167161
});
168162

169163
it('does not modify errors that are not SyntaxError instances', async function() {

0 commit comments

Comments
 (0)