gchq/CyberChef · error · OperationError
Invalid input
Error message
Invalid input
What it means
To BCD rejects input that is not a valid number — specifically when BigNumber.isNaN() is true. BCD (Binary-Coded Decimal) encodes decimal digits, so a non-numeric or unparseable input cannot be processed.
Source
Thrown at src/core/operations/ToBCD.mjs:61
"type": "boolean",
"value": false
},
{
"name": "Output format",
"type": "option",
"value": FORMAT
}
];
}
/**
* @param {BigNumber} input
* @param {Object[]} args
* @returns {string}
*/
run(input, args) {
if (input.isNaN())
throw new OperationError("Invalid input");
if (!input.integerValue(BigNumber.ROUND_DOWN).isEqualTo(input))
throw new OperationError("Fractional values are not supported by BCD");
const encoding = ENCODING_LOOKUP[args[0]],
packed = args[1],
signed = args[2],
outputFormat = args[3];
// Split input number up into separate digits
const digits = input.toFixed().split("");
if (digits[0] === "-" || digits[0] === "+") {
digits.shift();
}
let nibbles = [];
digits.forEach(d => {View on GitHub (pinned to 4290ea7539)
Solutions
- Ensure the input is a clean numeric value (digits and optional leading sign only).
- Precede To BCD with a 'To Decimal Number' / parsing step to coerce the value.
- Strip non-numeric characters from the input.
Example fix
// before: input = "12a3" -> NaN -> throws // after: input = 123 -> valid number, BCD encodes digits 1,2,3
Defensive patterns
Strategy: type-guard
Validate before calling
if (!BigNumber.isBigNumber(input) || input.isNaN()) {
throw new Error("To BCD requires a finite number");
} Type guard
const isValidBcdInput = v => BigNumber.isBigNumber(v) && !v.isNaN();
Try / catch
try { toBcd(input, ...args); }
catch (e) { if (/Invalid input/.test(e.message)) { /* parse/replace input to a number */ } else throw e; } Prevention
- Parse upstream output to a BigNumber before To BCD.
- Strip non-numeric characters from input.
- Reject NaN at the data boundary.
When it happens
Trigger: Feeding the operation a BigNumber that is NaN, e.g. a string like "abc" or "" parsed upstream into an invalid number, or any value the BigNumber layer considers NaN.
Common situations: Chaining To BCD after an operation that emits text rather than a number; passing an empty or whitespace-only input; locale-formatted numbers with commas that fail to parse.
Related errors
- Fractional values are not supported by BCD
- ${this.name} must be a number.
- ${this.name} must be an integer.
- ${this.name} must be greater than or equal to ${this.min}.
- ${this.name} must be less than or equal to ${this.max}.
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/f7621aa2d8137539.
Report an issue: GitHub.