diff --git a/src/apps.js b/src/apps.js index dbdc9354d..33018facf 100644 --- a/src/apps.js +++ b/src/apps.js @@ -1275,13 +1275,15 @@ async function scheduleTask(appId, installationState, taskId, auditSource) { debug(`scheduleTask: task ${taskId} of ${appId} completed. error: %o`, error); if (error?.code === tasks.ECRASHED || error?.code === tasks.ESTOPPED) { // if task crashed, update the error debug(`Apptask crashed/stopped: ${error.message}`); - const boxError = new BoxError(BoxError.TASK_ERROR, error.message); - boxError.details.crashed = error.code === tasks.ECRASHED; - boxError.details.stopped = error.code === tasks.ESTOPPED; - // see also apptask makeTaskError - boxError.details.taskId = taskId; - boxError.details.installationState = installationState; - await safe(update(appId, { installationState: exports.ISTATE_ERROR, error: boxError.toPlainObject(), taskId: null }), { debug }); + const appError = { + message: error.message, + reason: BoxError.TASK_ERROR, + crashed: error.code === tasks.ECRASHED, + stopped: error.code === tasks.ESTOPPED, + taskId, + installationState + }; + await safe(update(appId, { installationState: exports.ISTATE_ERROR, error: appError, taskId: null }), { debug }); } else if (!(installationState === exports.ISTATE_PENDING_UNINSTALL && !error)) { // clear out taskId except for successful uninstall await safe(update(appId, { taskId: null }), { debug }); } @@ -1297,7 +1299,7 @@ async function addTask(appId, installationState, task, auditSource) { assert.strictEqual(typeof auditSource, 'object'); const { args, values } = task; - // TODO: match the SQL logic to match checkAppState. this means checking the error.details.installationState and installationState. Unfortunately, former is JSON right now + // TODO: match the SQL logic to match checkAppState. this means checking the error.installationState and installationState. Unfortunately, former is JSON right now const requiredState = null; // 'requiredState' in task ? task.requiredState : exports.ISTATE_INSTALLED; const scheduleNow = 'scheduleNow' in task ? task.scheduleNow : true; const requireNullTaskId = 'requireNullTaskId' in task ? task.requireNullTaskId : true; @@ -1321,7 +1323,7 @@ function checkAppState(app, state) { if (app.installationState === exports.ISTATE_ERROR) { // allow task to be called again if that was the errored task - if (app.error.details.installationState === state) return null; + if (app.error.installationState === state) return null; // allow uninstall from any state if (state !== exports.ISTATE_PENDING_UNINSTALL && state !== exports.ISTATE_PENDING_RESTORE && state !== exports.ISTATE_PENDING_IMPORT) return new BoxError(BoxError.BAD_STATE, 'Not allowed in error state'); @@ -2251,7 +2253,7 @@ async function repair(app, data, auditSource) { assert.strictEqual(typeof auditSource, 'object'); const appId = app.id; - let errorState = (app.error && app.error.details.installationState) || exports.ISTATE_PENDING_CONFIGURE; + let errorState = (app.error && app.error.installationState) || exports.ISTATE_PENDING_CONFIGURE; const task = { args: {}, diff --git a/src/apptask.js b/src/apptask.js index be7bfec06..cc87b4071 100644 --- a/src/apptask.js +++ b/src/apptask.js @@ -44,10 +44,12 @@ function makeTaskError(error, app) { assert(error instanceof BoxError); assert.strictEqual(typeof app, 'object'); - // track a few variables which helps 'repair' restart the task (see also scheduleTask in apps.js) - error.details.taskId = app.taskId; - error.details.installationState = app.installationState; - return error.toPlainObject(); + return { + message: error.message, + reason: error.reason, + taskId: app.taskId, + installationState: app.installationState + }; } // updates the app object and the database diff --git a/src/boxerror.js b/src/boxerror.js index 742b09b42..f6debe481 100644 --- a/src/boxerror.js +++ b/src/boxerror.js @@ -75,7 +75,7 @@ BoxError.prototype.toPlainObject = function () { return { message: this.message, reason: this.reason, - details: this.details + ...this.details }; };