fix: handle empty generate image mode

This commit is contained in:
Кирилл Ветров 2026-06-25 12:33:29 +03:00
parent 0e50d32ec5
commit 64b63d86bc
2 changed files with 15 additions and 0 deletions

View File

@ -76,6 +76,10 @@ class GenerateImage extends Operation {
const bytesPerPixel = bytePerPixelMap[mode]; const bytesPerPixel = bytePerPixelMap[mode];
if (bytesPerPixel === undefined) {
throw new OperationError(`Unsupported Mode: (${mode})`);
}
if (bytesPerPixel > 0 && input.length % bytesPerPixel !== 0) { if (bytesPerPixel > 0 && input.length % bytesPerPixel !== 0) {
throw new OperationError( throw new OperationError(
`Number of bytes is not a divisor of ${bytesPerPixel}`, `Number of bytes is not a divisor of ${bytesPerPixel}`,

View File

@ -45,6 +45,17 @@ TestRegister.addTests([
{ op: "Render Image", args: ["Base64"] } { 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", name: "Extract EXIF: nothing",
input: "", input: "",