gchq/CyberChef · error · OperationError
Invalid encoding
Error message
Invalid encoding
What it means
Thrown in EncodeText.run when CHR_ENC_CODE_PAGES[args[0]] is falsy. The Encoding arg is an `option` dropdown whose values are exactly Object.keys(CHR_ENC_CODE_PAGES), so through the normal UI this error is effectively unreachable. It becomes reachable when a recipe is built or imported programmatically (Node API or hand-edited JSON) and references an encoding name absent from the table (typo, removed alias, or a name from a different CyberChef version).
Source
Thrown at src/core/operations/EncodeText.mjs:53
this.outputType = "ArrayBuffer";
this.args = [
{
"name": "Encoding",
"type": "option",
"value": Object.keys(CHR_ENC_CODE_PAGES)
}
];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
const format = CHR_ENC_CODE_PAGES[args[0]];
if (!format) {
throw new OperationError("Invalid encoding");
}
const encoded = cptable.utils.encode(format, input);
return new Uint8Array(encoded).buffer;
}
}
export default EncodeText;
View on GitHub (pinned to 4290ea7539)
Solutions
- Use an encoding name exactly as it appears in the operation's dropdown (it enumerates CHR_ENC_CODE_PAGES keys).
- For programmatic use, validate the name against Object.keys(CHR_ENC_CODE_PAGES) before calling.
- When importing recipes, confirm each encoding still exists in the target version.
- Avoid trailing spaces / case drift in encoding names.
Example fix
// before chef.encodeText(text, ['UTF8 ']); // typo/whitespace -> throws // after chef.encodeText(text, ['UTF-8']); // exact key from CHR_ENC_CODE_PAGES
Defensive patterns
Strategy: validation
Validate before calling
import { CHR_ENC_CODE_PAGES } from "../core/lib/ChrEnc.mjs";
const validEncodings = Object.keys(CHR_ENC_CODE_PAGES);
if (!validEncodings.includes(encoding)) throw new Error(`unknown encoding; pick one of: ${validEncodings.join(", ")}`); Type guard
const isKnownEncoding = (name) => Object.prototype.hasOwnProperty.call(CHR_ENC_CODE_PAGES, name);
Prevention
- When using the Node API, choose encoding names from Object.keys(CHR_ENC_CODE_PAGES).
- Validate imported recipe JSON encoding names against the current version's list.
- Avoid typos, trailing spaces, and case drift in encoding names.
When it happens
Trigger: args[0] is a string not present as a key in CHR_ENC_CODE_PAGES - a typo ('UTF-8 ' trailing space), a case mismatch, a name removed in this build, or an arbitrary string injected via recipe JSON / Node API bypassing the dropdown.
Common situations: Sharing a recipe across CyberChef versions where the encoding list changed; importing recipe JSON with a hand-typed encoding name; programmatic Node usage passing an unvalidated encoding string.
Related errors
- Invalid value
- Human-Readable Part (HRP) cannot be empty.
- HRP contains invalid character at position ${i}. Only printa
- Encoded string exceeds maximum length of 90 characters (got
- Incorrect number of samples.
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/838d4b7b5010ecba.
Report an issue: GitHub.