gchq/CyberChef · error · OperationError
${error}
Error message
${error} What it means
Protobuf Encode delegates to Protobuf.encode and wraps any thrown error in an OperationError surfaced as ${error}. Encode failures come from JSON that does not conform to the .proto schema: wrong field types, unknown field numbers, missing required fields, an invalid schema, or values that cannot be encoded (e.g. non-integer for an int64 field). The wrapper normalizes internal library errors into CyberChef's OperationError channel.
Source
Thrown at src/core/operations/ProtobufEncode.mjs:48
name: "Schema (.proto text)",
type: "text",
value: "",
rows: 8,
hint: "Drag and drop is enabled on this ingredient"
}
];
}
/**
* @param {Object} input
* @param {Object[]} args
* @returns {ArrayBuffer}
*/
run(input, args) {
try {
return Protobuf.encode(input, args);
} catch (error) {
throw new OperationError(error);
}
}
}
export default ProtobufEncode;
View on GitHub (pinned to 4290ea7539)
Solutions
- Ensure the .proto schema is valid (validate with protoc).
- Match JSON field names/numbers and types to the schema exactly.
- Read the wrapped ${error} message — it identifies the offending field/type.
- Start with 'Show Types' on a decode of a known-good message to learn the expected shape, then encode to match.
Example fix
// before: string where int64 expected
run({ id: "abc" }, [schema]);
// after: numeric value matching schema
run({ id: 123 }, [schema]); Defensive patterns
Strategy: try-catch
Validate before calling
// Validate schema parses and JSON keys match declared field numbers/types before encoding.
import protobuf from "protobufjs";
async function schemaIsValid(protoText) {
try { await protobuf.parse(protoText); return true; } catch { return false; }
} Type guard
function isPlainObject(v) {
return typeof v === "object" && v !== null && !Array.isArray(v);
} Try / catch
try {
return protobufEncode.run(inputObj, [schema]);
} catch (e) {
// e.message is the wrapped Protobuf.encode error; fix the offending field
throw e;
} Prevention
- Validate the .proto schema with protoc.
- Match JSON field names/numbers/types to the schema.
- Use 'Show Types' on a known-good decode to learn the expected shape.
When it happens
Trigger: Passing a JSON object whose keys/types do not match the .proto schema; an unparseable schema; a field value of the wrong type (string for an int field); missing required fields; enum values outside the declared set.
Common situations: Schema/data mismatch (encoding against a different schema than the producer used); hand-written JSON with typos in field names or numbers; an empty or invalid .proto; values like floats where integers are required.
Related errors
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/219eaa9259bf9f3f.
Report an issue: GitHub.