{"record":{"id":"45143ab7f0cb5c31","repo":"gchq/CyberChef","slug":"schema-error-schema-not-defined","errorCode":null,"errorMessage":"Schema Error: Schema not defined","messagePattern":"Schema Error: Schema not defined","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/lib/Protobuf.mjs","lineNumber":91,"sourceCode":"     * @param {byteArray} input\n     * @returns {number}\n     */\n    static varIntDecode(input) {\n        const pb = new Protobuf(input);\n        return pb._varInt();\n    }\n\n    /**\n     * Encode input JSON according to the given schema\n     *\n     * @param {Object} input\n     * @param {Object []} args\n     * @returns {Object}\n     */\n    static encode(input, args) {\n        this.updateProtoRoot(args[0]);\n        if (!this.mainMessageName) {\n            throw new Error(\"Schema Error: Schema not defined\");\n        }\n        const message = this.parsedProto.root.nested[this.mainMessageName];\n\n        // Convert input into instance of message, and verify instance\n        input = message.fromObject(input);\n        const error = message.verify(input);\n        if (error) {\n            throw new Error(\"Input Error: \" + error);\n        }\n        // Encode input\n        const output = message.encode(input).finish();\n        return new Uint8Array(output).buffer;\n    }\n\n    /**\n     * Parse Protobuf data\n     *\n     * @param {byteArray} input","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/Protobuf.mjs#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nProtobuf.encode(input, ['']);\n// after\nProtobuf.encode(input, ['syntax = \"proto3\";\\nmessage Person { string name = 1; }']);","handlingStrategy":"validation","validationCode":"Protobuf.updateProtoRoot(protoText);\nif (!Protobuf.mainMessageName) {\n  throw new Error('Schema has no top-level message; cannot encode.');\n}\nreturn Protobuf.encode(input, [protoText]);","typeGuard":"function schemaHasMessage(protoText) {\n  try {\n    protobuf.parse(protoText);\n    return /\\bmessage\\s+\\w+/m.test(protoText);\n  } catch { return false; }\n}","tryCatchPattern":"try {\n  return Protobuf.encode(input, [protoText]);\n} catch (e) {\n  if (/Schema not defined/.test(e.message)) {\n    // prompt user for a .proto containing at least one top-level message\n  }\n  throw e;\n}","preventionTips":["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."],"tags":["protobuf","schema","encode","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}