{"record":{"id":"a73d46cdbe0c38b3","repo":"gchq/CyberChef","slug":"unsupported-mode-mode","errorCode":null,"errorMessage":"Unsupported Mode: (${mode})","messagePattern":"Unsupported Mode: \\((.+?)\\)","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/GenerateImage.mjs","lineNumber":84,"sourceCode":"    /**\n     * @param {byteArray} input\n     * @param {Object[]} args\n     * @returns {ArrayBuffer}\n     */\n    async run(input, args) {\n        const [mode, scale, width] = args;\n        input = new Uint8Array(input);\n\n        const bytePerPixelMap = {\n            Greyscale: 1,\n            RG: 2,\n            RGB: 3,\n            RGBA: 4,\n            Bits: 1 / 8,\n        };\n\n        if (!Object.hasOwn(bytePerPixelMap, mode)) {\n            throw new OperationError(`Unsupported Mode: (${mode})`);\n        }\n\n        const bytesPerPixel = bytePerPixelMap[mode];\n\n        if (bytesPerPixel > 0 && input.length % bytesPerPixel !== 0) {\n            throw new OperationError(\n                `Number of bytes is not a divisor of ${bytesPerPixel}`,\n            );\n        }\n\n        const height = Math.ceil(input.length / bytesPerPixel / width);\n        const image = new Jimp({ width, height });\n\n        if (isWorkerEnvironment())\n            self.sendStatusMessage(\"Generating image from data...\");\n\n        if (mode === \"Bits\") {\n            let index = 0;","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/GenerateImage.mjs#L66-L102","documentation":"Thrown by GenerateImage when the 'mode' argument is not one of the recognized pixel-format keys: Greyscale, RG, RGB, RGBA, or Bits. The operation maps each mode to a bytes-per-pixel value and refuses unknown modes before processing input. This guards the downstream pixel-writing loop from an out-of-range switch fallthrough.","triggerScenarios":"Passing a mode string not present in bytePerPixelMap — e.g. 'CMYK', 'BGR', 'GRAY', a typo like 'RBGA', or a localized/case variant. Also triggered if args[0] is undefined or null because the recipe was constructed programmatically without a mode.","commonSituations":"Programmatically building a recipe and forgetting to set the mode ingredient, or a UI dropdown change that submits a stale enum value after an operation update.","solutions":["Set the mode argument to one of: Greyscale, RG, RGB, RGBA, or Bits.","If building recipes in code, validate that mode is in the allowed set before invoking the operation.","Check the operation's ingList/config for the current list of supported mode values."],"exampleFix":"// before\nargs[0] = \"CMYK\";\n// after\nargs[0] = \"RGBA\"; // one of Greyscale|RG|RGB|RGBA|Bits","handlingStrategy":"type-guard","validationCode":"const VALID_MODES = [\"Greyscale\", \"RG\", \"RGB\", \"RGBA\", \"Bits\"];\nif (!VALID_MODES.includes(mode)) {\n  // reject before calling GenerateImage\n}","typeGuard":"function isImageMode(m) {\n  return [\"Greyscale\", \"RG\", \"RGB\", \"RGBA\", \"Bits\"].includes(m);\n}","tryCatchPattern":null,"preventionTips":["Restrict the mode UI control to the five known values.","When constructing recipes programmatically, assert the mode against the known set."],"tags":["image","argument-validation","enum","user-input"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}