Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent UnhandledPromiseRejectionWarning when module resolution/parsing fails #4228

Merged
merged 2 commits into from Sep 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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'");
}
};