simplify error handling and simplify markModuleAsErrored as its always called with an error

This commit is contained in:
Tim Sebastian 2017-02-13 21:38:55 +11:00
parent b9507cca99
commit a5d5b9ef55
1 changed files with 11 additions and 13 deletions

View File

@ -173,7 +173,8 @@ class NormalModule extends Module {
}
if(err) {
return callback(this.error = new ModuleBuildError(this, err));
const error = new ModuleBuildError(this, err);
return callback(error);
}
const resourceBuffer = result.resourceBuffer;
@ -181,8 +182,8 @@ class NormalModule extends Module {
const sourceMap = result.result[1];
if(!Buffer.isBuffer(source) && typeof source !== "string") {
this.error = new ModuleBuildError(this, new Error("Final loader didn't return a Buffer or String"));
return callback(this.error);
const error = new ModuleBuildError(this, new Error("Final loader didn't return a Buffer or String"));
return callback(error);
}
this._source = this.createSource(asString(source), resourceBuffer, sourceMap);
@ -195,14 +196,11 @@ class NormalModule extends Module {
super.disconnect();
}
markModuleAsErrored() {
markModuleAsErrored(error) {
this.meta = null;
if(this.error) {
this.errors.push(this.error);
this._source = new RawSource("throw new Error(" + JSON.stringify(this.error.message) + ");");
} else {
this._source = new RawSource("throw new Error('Module build failed');");
}
this.error = error;
this.errors.push(this.error);
this._source = new RawSource("throw new Error(" + JSON.stringify(this.error.message) + ");");
}
applyNoParseRule(rule, request) {
@ -259,7 +257,7 @@ class NormalModule extends Module {
// if we have an error mark module as failed and exit
if(err) {
this.markModuleAsErrored();
this.markModuleAsErrored(err);
return callback();
}
@ -279,8 +277,8 @@ class NormalModule extends Module {
});
} catch(e) {
const source = this._source.source();
this.error = new ModuleParseError(this, source, e);
this.markModuleAsErrored();
const error = new ModuleParseError(this, source, e);
this.markModuleAsErrored(error);
return callback();
}
return callback();