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 error logging when thrown errors are strings #1761

Merged
merged 1 commit into from Jul 21, 2018
Merged
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
38 changes: 23 additions & 15 deletions 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;
}
Copy link
Contributor

@fathyb fathyb Jul 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we return something like new Error('Unknown error'), or do it in errorToJson?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not even sure why it would ever throw something else than an Error object.

I guess I can add a fallback for unknown error

}

exports.errorToJson = errorToJson;
Expand Down