Ver código fonte

Report proper error when an operation is invalid

KernelDeimos 1 ano atrás
pai
commit
653898b463

+ 4 - 0
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 }) => {

+ 6 - 0
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) +