tasks: make error a json

also, handle case where we never got to handle task exit cleanly
This commit is contained in:
Girish Ramakrishnan
2019-08-30 13:46:55 -07:00
parent dd0fb8292c
commit bd23abd265
6 changed files with 57 additions and 21 deletions

View File

@@ -57,7 +57,12 @@ initialize(function (error) {
const progressCallback = (progress, cb) => tasks.update(taskId, progress, cb || NOOP_CALLBACK);
const resultCallback = (error, result) => {
const progress = { percent: 100, result: result || null, errorMessage: error ? error.message : null };
// Error object has properties with enumerable: false (https://mattcbaker.com/posts/stringify-javascript-error/)
const progress = {
percent: 100,
result: result || null,
error: error ? JSON.parse(JSON.stringify(error, Object.getOwnPropertyNames(error))) : null
};
tasks.update(taskId, progress, () => process.exit(error ? 50 : 0));
};