Skip to content

Commit

Permalink
support error strings (#1761)
Browse files Browse the repository at this point in the history
  • Loading branch information
DeMoorJasper authored and devongovett committed Jul 21, 2018
1 parent 8696020 commit 5380311
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions packages/core/parcel/src/workerfarm/errorUtils.js
@@ -1,22 +1,30 @@
function errorToJson(error) {
let jsonError = {
message: error.message,
stack: error.stack,
name: error.name
};
// Add all custom codeFrame properties
Object.keys(error).forEach(key => {
jsonError[key] = error[key];
});
return jsonError;
if (typeof error === 'string') {
return {message: error};
}

if (error instanceof Error) {
let jsonError = {
message: error.message,
stack: error.stack,
name: error.name
};
// Add all custom codeFrame properties
Object.keys(error).forEach(key => {
jsonError[key] = error[key];
});
return jsonError;
}
}

function jsonToError(json) {
let error = new Error(json.message);
Object.keys(json).forEach(key => {
error[key] = json[key];
});
return error;
if (json) {
let error = new Error(json.message);
Object.keys(json).forEach(key => {
error[key] = json[key];
});
return error;
}
}

exports.errorToJson = errorToJson;
Expand Down

0 comments on commit 5380311

Please sign in to comment.