From 653898b4635c1605fbeddef70dc79dca8832810a Mon Sep 17 00:00:00 2001 From: KernelDeimos Date: Mon, 15 Apr 2024 22:27:03 -0400 Subject: [PATCH] Report proper error when an operation is invalid --- packages/backend/src/api/APIError.js | 4 ++++ packages/backend/src/filesystem/batch/BatchExecutor.js | 6 ++++++ 2 files changed, 10 insertions(+) diff --git a/packages/backend/src/api/APIError.js b/packages/backend/src/api/APIError.js index 216eddbbd9..9209223648 100644 --- a/packages/backend/src/api/APIError.js +++ b/packages/backend/src/api/APIError.js @@ -128,6 +128,10 @@ module.exports = class APIError { return `Invalid id`; } }, + 'invalid_operation': { + status: 400, + message: ({ operation }) => `Invalid operation: ${quot(operation)}.`, + }, 'field_invalid': { status: 400, message: ({ key, expected, got }) => { diff --git a/packages/backend/src/filesystem/batch/BatchExecutor.js b/packages/backend/src/filesystem/batch/BatchExecutor.js index fcc8e343c2..8356ad6b23 100644 --- a/packages/backend/src/filesystem/batch/BatchExecutor.js +++ b/packages/backend/src/filesystem/batch/BatchExecutor.js @@ -85,6 +85,12 @@ class BatchExecutor extends AdvancedBase { if ( ! x ) throw new Error('no context'); try { + if ( ! command_cls ) { + throw APIError.create('invalid_operation', null, { + operation: op.op, + }); + } + if ( file ) workUnit.checkpoint( 'about to run << ' + (file.originalname ?? file.name) +