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: "",