{"record":{"id":"a3a7e312668ba9c3","repo":"gchq/CyberChef","slug":"invalid-encoding","errorCode":null,"errorMessage":"Invalid encoding","messagePattern":"Invalid encoding","errorType":"exception","errorClass":"OperationError","httpStatus":null,"severity":"error","filePath":"src/core/operations/DecodeText.mjs","lineNumber":53,"sourceCode":"        this.outputType = \"string\";\n        this.args = [\n            {\n                \"name\": \"Encoding\",\n                \"type\": \"option\",\n                \"value\": Object.keys(CHR_ENC_CODE_PAGES)\n            }\n        ];\n    }\n\n    /**\n     * @param {ArrayBuffer} input\n     * @param {Object[]} args\n     * @returns {string}\n     */\n    run(input, args) {\n        const format = CHR_ENC_CODE_PAGES[args[0]];\n        if (!format) {\n            throw new OperationError(\"Invalid encoding\");\n        }\n        return cptable.utils.decode(format, new Uint8Array(input));\n    }\n\n}\n\nexport default DecodeText;\n","sourceCodeStart":35,"sourceCodeEnd":61,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/operations/DecodeText.mjs#L35-L61","documentation":"Thrown by Decode Text run() when the selected encoding name does not resolve to a code page id in the CHR_ENC_CODE_PAGES map. The args are nominally constrained by the operation's option list, so through the UI this is effectively unreachable; it surfaces only when the operation is invoked programmatically with an encoding string not present in the registry.","triggerScenarios":"Calling run() directly with args[0] set to a string that is not a key of CHR_ENC_CODE_PAGES - e.g. 'utf-8' instead of 'UTF-8', a typo, an unsupported legacy code page name, or undefined after an arg mapping mistake.","commonSituations":"Programmatic/Node-API invocation passing a casing-mismatched or unregistered encoding name; a recipe imported with a stale encoding name removed in a newer build; an automation script hardcoding a charset string.","solutions":["Use an exact encoding name from Object.keys(CHR_ENC_CODE_PAGES) (case-sensitive, e.g. 'UTF-8' not 'utf8').","If building a recipe dynamically, validate the encoding against the registry before invoking.","Regenerate the recipe in the current build so the option value matches the registry."],"exampleFix":"// before\nop.run(input, [{0: \"utf8\"}]);\n// or\nop.run(input, [\"utf8\"]); // not in registry\n\n// after\nop.run(input, [\"UTF-8\"]); // exact registry key","handlingStrategy":"validation","validationCode":"import { CHR_ENC_CODE_PAGES } from \"src/core/lib/ChrEnc.mjs\";\n\nfunction isSupportedEncoding(name) {\n    return Object.prototype.hasOwnProperty.call(CHR_ENC_CODE_PAGES, name);\n}","typeGuard":"/** @returns {boolean} */\nfunction isValidCodePage(name) {\n    return typeof name === \"string\"\n        && Object.prototype.hasOwnProperty.call(CHR_ENC_CODE_PAGES, name);\n}","tryCatchPattern":"try {\n    out = decodeText.run(input, args);\n} catch (e) {\n    if (e instanceof OperationError && e.message === \"Invalid encoding\") {\n        // pick a default (e.g. 'UTF-8') or surface supported list\n        args[0] = \"UTF-8\";\n        out = decodeText.run(input, args);\n    } else throw e;\n}","preventionTips":["Use exact encoding names from Object.keys(CHR_ENC_CODE_PAGES) (case-sensitive).","When invoking programmatically, validate the encoding against the registry first.","Regenerate imported recipes in the current build to align option values.","Default to 'UTF-8' as a safe fallback when the source encoding is unknown."],"tags":["encoding","codepage","validation","programmatic"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}