Skip to content

Commit

Permalink
fix: prevent UnhandledPromiseRejectionWarning when module resolution/…
Browse files Browse the repository at this point in the history
…parsing fails (#4228)

* fix: prevent UnhandledPromiseRejectionWarning from module resolution/parsing fails

* Account for changed Node 16 error messages

Co-authored-by: Lukas Taegert-Atkinson <lukas.taegert-atkinson@tngtech.com>
  • Loading branch information
kherock and lukastaegert committed Sep 18, 2021
1 parent bce7624 commit 2ff8fc1
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 16 deletions.
6 changes: 5 additions & 1 deletion src/ModuleLoader.ts
Expand Up @@ -341,7 +341,11 @@ export class ModuleLoader {
Promise.all([
...(resolveStaticDependencyPromises as Promise<never>[]),
...(resolveDynamicImportPromises as Promise<never>[])
]).then(() => this.pluginDriver.hookParallel('moduleParsed', [module.info]));
])
.then(() => this.pluginDriver.hookParallel('moduleParsed', [module.info]))
.catch(() => {
/* rejections thrown here are also handled within PluginDriver - they are safe to ignore */
});
await Promise.all([
this.fetchStaticDependencies(module, resolveStaticDependencyPromises),
this.fetchDynamicDependencies(module, resolveDynamicImportPromises)
Expand Down
4 changes: 1 addition & 3 deletions test/function/samples/es5-class-called-without-new/main.js
Expand Up @@ -2,6 +2,4 @@ import { Foo, Bar } from './foo';

assert.equal( new Foo(5).value, 5 );

assert.throws( function () {
Bar(5);
}, /^TypeError: Cannot set property 'value' of undefined$/ );
assert.throws(() => Bar(5), /^TypeError: Cannot set propert.*'value'.*$/ );
8 changes: 0 additions & 8 deletions test/function/samples/object-deep-access-effect/_config.js
@@ -1,5 +1,3 @@
const assert = require('assert');

module.exports = {
description: 'throws when an nested property of an unknown object property is accessed',
context: {
Expand All @@ -9,11 +7,5 @@ module.exports = {
},
options: {
external: ['external']
},
exports({ expectError }) {
assert.throws(expectError, {
name: 'TypeError',
message: "Cannot read property 'prop' of undefined"
});
}
};
4 changes: 2 additions & 2 deletions test/function/samples/object-deep-access-effect/main.js
@@ -1,6 +1,6 @@
import { unknown } from 'external';

export function expectError() {
assert.throws(() => {
const obj = {};
obj[unknown].prop;
}
}, /^TypeError: Cannot read propert.*'prop'.*$/ );
5 changes: 3 additions & 2 deletions test/function/samples/warn-on-top-level-this/_config.js
@@ -1,5 +1,5 @@
const assert = require('assert');
const path = require('path');
const { assertIncludes } = require('../../../utils.js');

module.exports = {
description: 'warns on top-level this (#770)',
Expand All @@ -24,6 +24,7 @@ module.exports = {
}
],
runtimeError: err => {
assert.equal(err.message, `Cannot set property 'foo' of undefined`);
assertIncludes(err.message, 'Cannot set propert');
assertIncludes(err.message, "'foo'");
}
};

0 comments on commit 2ff8fc1

Please sign in to comment.