{"record":{"id":"73a4b4c213218891","repo":"gchq/CyberChef","slug":"schema-error","errorCode":null,"errorMessage":"Schema ${error}","messagePattern":"Schema (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/lib/Protobuf.mjs","lineNumber":132,"sourceCode":"        this.showUnknownFields = args[1];\n        this.showTypes = args[2];\n        return this.mergeDecodes(input);\n    }\n\n    /**\n     * Update the parsedProto, throw parsing errors\n     *\n     * @param {string} protoText\n     */\n    static updateProtoRoot(protoText) {\n        try {\n            this.parsedProto = protobuf.parse(protoText);\n            if (this.parsedProto.package) {\n                this.parsedProto.root = this.parsedProto.root.nested[this.parsedProto.package];\n            }\n            this.updateMainMessageName();\n        } catch (error) {\n            throw new Error(\"Schema \" + error);\n        }\n    }\n\n    /**\n     * Set mainMessageName to the first instance of a message defined in the schema that is not a submessage\n     *\n     */\n    static updateMainMessageName() {\n        const messageNames = [];\n        const fieldTypes = [];\n        this.parsedProto.root.nestedArray.forEach(block => {\n            if (block instanceof protobuf.Type) {\n                messageNames.push(block.name);\n                this.parsedProto.root.nested[block.name].fieldsArray.forEach(field => {\n                    fieldTypes.push(field.type);\n                });\n            }\n        });","sourceCodeStart":114,"sourceCodeEnd":150,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/Protobuf.mjs#L114-L150","documentation":"Thrown by Protobuf.updateProtoRoot when protobufjs `protobuf.parse(protoText)` raises an exception — the .proto text is syntactically invalid. The original parse error text is appended after 'Schema '.","triggerScenarios":"Calling encode/decode paths with a malformed .proto: missing semicolons, unbalanced braces, illegal field labels, duplicate field numbers, invalid type references, or non-protobuf text entirely.","commonSituations":"Hand-typed .proto with syntax errors; copy-paste truncation; using proto2 syntax features without `syntax = \"proto2\"`; trailing whitespace/comments breaking older protobufjs versions.","solutions":["Read the appended protobufjs parse error for the line/column of the syntax fault.","Validate the .proto with `protoc --proto_path=. --descriptor_set_out=/dev/null schema.proto` or `protobuf.parse` standalone before use.","Ensure the schema begins with the correct `syntax` declaration."],"exampleFix":"// before\nconst proto = 'message Person { string name }'; // missing semicolon\n// after\nconst proto = 'syntax = \"proto3\";\\nmessage Person { string name = 1; }';","handlingStrategy":"try-catch","validationCode":"try {\n  protobuf.parse(protoText);\n} catch (e) {\n  throw new Error('Proto schema is syntactically invalid: ' + e.message);\n}","typeGuard":"function isValidProto(protoText) {\n  try { protobuf.parse(protoText); return true; } catch { return false; }\n}","tryCatchPattern":"try {\n  return Protobuf.encode(input, [protoText]);\n} catch (e) {\n  if (/^Schema /.test(e.message)) {\n    // e.message contains the protobufjs parse error with line info\n  }\n  throw e;\n}","preventionTips":["Lint the .proto with protoc or protobuf.parse before feeding it in.","Begin every schema with the correct `syntax` declaration.","Avoid hand-retyping schemas; load them from a checked-in file."],"tags":["protobuf","schema","parse","validation"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}