boxerror: details is not a subobject

This commit is contained in:
Girish Ramakrishnan
2025-10-17 20:25:46 +02:00
parent 0fb8914b67
commit 5bd6001f95
3 changed files with 19 additions and 15 deletions

View File

@@ -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: {},