{"record":{"id":"cdf20e54007c8efd","repo":"gchq/CyberChef","slug":"input-error-error","errorCode":null,"errorMessage":"Input Error: ${error}","messagePattern":"Input Error: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/lib/Protobuf.mjs","lineNumber":99,"sourceCode":"    /**\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\n     * @returns {Object}\n     */\n    static decode(input, args) {\n        this.updateProtoRoot(args[0]);\n        this.showUnknownFields = args[1];\n        this.showTypes = args[2];\n        return this.mergeDecodes(input);\n    }","sourceCodeStart":81,"sourceCodeEnd":117,"githubUrl":"https://github.com/gchq/CyberChef/blob/4290ea753912378913b1f3f54e0fc5720afeda5d/src/core/lib/Protobuf.mjs#L81-L117","documentation":"Thrown by Protobuf.encode when protobufjs `message.verify(input)` returns a non-empty error string — i.e. the supplied JSON/object does not satisfy the schema for the resolved message type. The original protobufjs message is appended.","triggerScenarios":"Calling encode with input missing required fields, wrong field types (e.g. string where int32 is expected), out-of-range enum values, malformed bytes fields, or extra fields that violate schema under strict parsing.","commonSituations":"Mismatch between user-supplied JSON and the .proto (field renamed, type changed, required field missing in proto2); sending numbers as strings; invalid enum names; bytes fields not provided as base64/ArrayBuffer.","solutions":["Read the appended protobufjs message — it names the offending field and the constraint violated.","Align the input JSON to the schema: correct types, fill required fields, remove unknown fields.","Validate with `message.verify(input)` separately first and log its full output before encode."],"exampleFix":"// before: schema expects int32 age, input has string\nProtobuf.encode({name:'A', age:'30'}, [proto]);\n// after\nProtobuf.encode({name:'A', age:30}, [proto]);","handlingStrategy":"validation","validationCode":"Protobuf.updateProtoRoot(protoText);\nconst message = Protobuf.parsedProto.root.nested[Protobuf.mainMessageName];\nconst obj = message.fromObject(input);\nconst verifyErr = message.verify(obj);\nif (verifyErr) throw new Error('Input does not match schema: ' + verifyErr);\nreturn Protobuf.encode(input, [protoText]);","typeGuard":"function inputMatchesMessage(message, input) {\n  return !message.verify(message.fromObject(input));\n}","tryCatchPattern":"try {\n  return Protobuf.encode(input, [protoText]);\n} catch (e) {\n  if (/^Input Error:/.test(e.message)) {\n    // e.message after 'Input Error: ' names the failing field\n  }\n  throw e;\n}","preventionTips":["Run message.verify separately first and show its field-level diagnostics.","Keep JSON field names and types in lock-step with the .proto.","Provide enum values by name or valid number, never arbitrary strings."],"tags":["protobuf","schema","encode","validation","input-error"],"backgroundTag":null,"analyzedSha":"4290ea753912378913b1f3f54e0fc5720afeda5d","analyzedAt":"2026-08-13T06:05:50.210Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}