gchq/CyberChef · error · OperationError
Invalid encode option
Error message
Invalid encode option
What it means
Thrown by Rison Encode when the encodeOption argument is not one of 'Encode', 'Encode Object', 'Encode Array', or 'Encode URI'. The argument is a fixed option dropdown, so this is only reachable through direct API calls with an invalid string.
Source
Thrown at src/core/operations/RisonEncode.mjs:54
/**
* @param {Object} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
const [encodeOption] = args;
switch (encodeOption) {
case "Encode":
return rison.encode(input);
case "Encode Object":
return rison.encode_object(input);
case "Encode Array":
return rison.encode_array(input);
case "Encode URI":
return rison.encode_uri(input);
default:
throw new OperationError("Invalid encode option");
}
}
}
export default RisonEncode;
View on GitHub (pinned to 4290ea7539)
Solutions
- Use one of the four exact option strings: 'Encode', 'Encode Object', 'Encode Array', 'Encode URI'.
- Match the option to the input type — 'Encode Object' expects a plain object, 'Encode Array' expects an array.
Example fix
// before
risonEncode.run({a:1}, ["encode"])
// after
risonEncode.run({a:1}, ["Encode Object"]) Defensive patterns
Strategy: validation
Validate before calling
const VALID_ENCODE = ["Encode", "Encode Object", "Encode Array", "Encode URI"];
if (!VALID_ENCODE.includes(encodeOption)) {
throw new Error(`encodeOption must be one of ${VALID_ENCODE.join(", ")}`);
} Type guard
function isRisonEncodeOption(v) {
return ["Encode", "Encode Object", "Encode Array", "Encode URI"].includes(v);
} Prevention
- Use the exact option strings from the constructor.
- Match the option to the input data type (object vs array).
When it happens
Trigger: Programmatically calling RisonEncode.run(input, ['BadValue']) or passing an args array whose first element doesn't match a case. Malformed input objects instead throw from the rison library itself.
Common situations: Node API usage with a hard-coded option string that is misspelled or from an older schema; recipe JSON referencing a renamed option.
Related errors
- Invalid Decode option
- Invalid size
- Failed to set value of ingredient '${this._ingList[i].name}'
- Invalid Base64 alphabet length (${alphabet.length}): ${alpha
- Invalid value
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/d7e91827116b5a8c.
Report an issue: GitHub.