gchq/CyberChef · error · OperationError
${err.toString()}
Error message
${err.toString()} What it means
Generic catch-all thrown by BSONSerialise.run when either JSON.parse(input) or the bson serialize() throws. The operation first parses the input as JSON, then serialises the resulting value to BSON; a JSON syntax error or a value BSON cannot represent (e.g. deeply nested object, unsupported type, key containing a null byte) surfaces as the original Error.toString() in the message.
Source
Thrown at src/core/operations/BSONSerialise.mjs:44
this.inputType = "string";
this.outputType = "ArrayBuffer";
this.args = [];
}
/**
* @param {string} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
if (!input) return new ArrayBuffer();
try {
const data = JSON.parse(input);
const result = serialize(data);
return result.buffer.slice(result.byteOffset, result.byteOffset + result.byteLength);
} catch (err) {
throw new OperationError(err.toString());
}
}
}
export default BSONSerialise;
View on GitHub (pinned to 4290ea7539)
Solutions
- Validate the input as well-formed JSON first (e.g. with a JSON linter or JSON.parse in isolation).
- Ensure all values are BSON-compatible types (use strings/dates for large numbers).
- Inspect the forwarded Error.toString() message for the exact parse or serialise failure.
Example fix
// before - single quotes / unquoted keys
chef.bSONSerialise("{a: '1'}");
// after - valid JSON
chef.bSONSerialise('{"a":1}'); Defensive patterns
Strategy: validation
Validate before calling
function assertJsonForBson(input) {
let data;
try { data = JSON.parse(input); } catch (e) {
throw new Error(`Input is not valid JSON: ${e.message}`);
}
if (data === undefined) throw new Error("JSON parsed to undefined; not BSON-representable");
return data;
}
assertJsonForBson(input); Type guard
function isParsableJson(s) {
try { JSON.parse(s); return true; } catch { return false; }
} Try / catch
try {
chef.bSONSerialise(input);
} catch (e) {
if (/JSON|position|Unexpected/i.test(e.message)) {
throw new Error(`Invalid JSON for BSON: ${e.message}`);
}
throw e;
} Prevention
- Run the input through a JSON linter or JSON.parse first.
- Use JSON (double quotes), not JS object literals.
- Avoid values BSON cannot represent (undefined, functions, oversized integers).
When it happens
Trigger: Input that is not valid JSON (trailing comma, unquoted keys, single quotes), or valid JSON whose values are not BSON-representable (e.g. very large numbers losing precision, undefined, functions, or symbol-keyed objects).
Common situations: Pasting hand-written JSON with syntax errors; feeding a JS object literal instead of JSON; numbers exceeding BSON's 64-bit integer range; keys with null bytes.
Related errors
- ${err.toString()}
- Unable to stringify YAML: ${err}
- Could not encode JSON to MessagePack: ${err}
- Unsupported QR code format.
- Invalid hash
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/ca242da57f26ddf6.
Report an issue: GitHub.