Skip to content

Commit

Permalink
fix(webpack): accept object argument in BuildError
Browse files Browse the repository at this point in the history
  • Loading branch information
jhiode authored and herschel666 committed Oct 9, 2020
1 parent fef7d0e commit 9e91b96
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions packages/webpack/lib/utils/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,20 @@ function deserializeError(data) {
exports.deserializeError = deserializeError;

class BuildError extends Error {
constructor(stack) {
super();
this.name = this.constructor.name;
this.stack = `${this.name}: ${stripAnsi(stack)}`;
this.message = this.stack.slice(0, this.stack.indexOf(EOL));
constructor(error) {
if (typeof error === 'object' && error) {
super(error.message);

Object.assign(this, error);
} else if (typeof error === 'string') {
const [message, ...lines] = stripAnsi(error).split(EOL);

super(message);

this.stack = lines.join(EOL);
} else {
super();
}
}

toJSON() {
Expand Down

0 comments on commit 9e91b96

Please sign in to comment.