From 64b63d86bcf3075f65b4e70ea5f8eb2c8a3b77e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB=20=D0=92=D0=B5=D1=82?= =?UTF-8?q?=D1=80=D0=BE=D0=B2?= Date: Thu, 25 Jun 2026 12:33:29 +0300 Subject: [PATCH] fix: handle empty generate image mode --- src/core/operations/GenerateImage.mjs | 4 ++++ tests/operations/tests/Image.mjs | 11 +++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/core/operations/GenerateImage.mjs b/src/core/operations/GenerateImage.mjs index 053e4ba1..56b5798a 100644 --- a/src/core/operations/GenerateImage.mjs +++ b/src/core/operations/GenerateImage.mjs @@ -76,6 +76,10 @@ class GenerateImage extends Operation { const bytesPerPixel = bytePerPixelMap[mode]; + if (bytesPerPixel === undefined) { + throw new OperationError(`Unsupported Mode: (${mode})`); + } + if (bytesPerPixel > 0 && input.length % bytesPerPixel !== 0) { throw new OperationError( `Number of bytes is not a divisor of ${bytesPerPixel}`, diff --git a/tests/operations/tests/Image.mjs b/tests/operations/tests/Image.mjs index 1f450433..fe6cab10 100644 --- a/tests/operations/tests/Image.mjs +++ b/tests/operations/tests/Image.mjs @@ -45,6 +45,17 @@ TestRegister.addTests([ { op: "Render Image", args: ["Base64"] } ] }, + { + name: "Generate Image: empty mode", + input: "", + expectedOutput: "Unsupported Mode: ()", + recipeConfig: [ + { + op: "Generate Image", + args: ["", 8, 64] + } + ] + }, { name: "Extract EXIF: nothing", input: "",