gchq/CyberChef · error · Error
Schema Error: Schema not defined
Error message
Schema Error: Schema not defined
What it means
Thrown by Protobuf.encode when, after parsing the supplied .proto schema, no main message name could be determined (mainMessageName is null). encode() needs a concrete message type to serialise against; without one it cannot proceed.
Source
Thrown at src/core/lib/Protobuf.mjs:91
* @param {byteArray} input
* @returns {number}
*/
static varIntDecode(input) {
const pb = new Protobuf(input);
return pb._varInt();
}
/**
* Encode input JSON according to the given schema
*
* @param {Object} input
* @param {Object []} args
* @returns {Object}
*/
static encode(input, args) {
this.updateProtoRoot(args[0]);
if (!this.mainMessageName) {
throw new Error("Schema Error: Schema not defined");
}
const message = this.parsedProto.root.nested[this.mainMessageName];
// Convert input into instance of message, and verify instance
input = message.fromObject(input);
const error = message.verify(input);
if (error) {
throw new Error("Input Error: " + error);
}
// Encode input
const output = message.encode(input).finish();
return new Uint8Array(output).buffer;
}
/**
* Parse Protobuf data
*
* @param {byteArray} inputView on GitHub (pinned to 4290ea7539)
Solutions
- Provide a .proto schema that declares at least one top-level `message`.
- Verify the schema parses and yields a mainMessageName (call Protobuf.updateProtoRoot(protoText) and inspect mainMessageName) before encode.
- Check that the schema text was not truncated or passed as the wrong arg index.
Example fix
// before
Protobuf.encode(input, ['']);
// after
Protobuf.encode(input, ['syntax = "proto3";\nmessage Person { string name = 1; }']); Defensive patterns
Strategy: validation
Validate before calling
Protobuf.updateProtoRoot(protoText);
if (!Protobuf.mainMessageName) {
throw new Error('Schema has no top-level message; cannot encode.');
}
return Protobuf.encode(input, [protoText]); Type guard
function schemaHasMessage(protoText) {
try {
protobuf.parse(protoText);
return /\bmessage\s+\w+/m.test(protoText);
} catch { return false; }
} Try / catch
try {
return Protobuf.encode(input, [protoText]);
} catch (e) {
if (/Schema not defined/.test(e.message)) {
// prompt user for a .proto containing at least one top-level message
}
throw e;
} Prevention
- Always include at least one top-level `message` in the .proto.
- Validate the schema parses and yields a mainMessageName before encode.
- Keep the schema text as the first element of the args array.
When it happens
Trigger: Calling Protobuf.encode(input, [protoText]) where protoText is empty, contains only enums/services, defines only nested submessages that updateMainMessageName rejects, or where updateMainMessageName found zero top-level protobuf.Type entries.
Common situations: Empty schema string passed from the UI; a .proto that only declares `enum` or `package` with no `message`; schema whose only messages are filtered out; forgotten schema argument.
Related errors
- Input Error: ${error}
- Schema ${error}
- Input ${error}
- Exhausted Buffer
- Unknown type 0x${type.toString(16)}
AI-assisted analysis of gchq/CyberChef@4290ea7539 (2026-08-13).
Data as JSON: /api/errors/45143ab7f0cb5c31.
Report an issue: GitHub.