{"record":{"id":"f97bbaff955843f0","repo":"hyperledger/fabric","slug":"error-decoding-input","errorCode":null,"errorMessage":"error decoding input","messagePattern":"error decoding input","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/configtxlator/main.go","lineNumber":143,"sourceCode":"\tfmt.Println(metadata.GetVersionInfo())\n}\n\nfunc encodeProto(msgName string, input, output *os.File) error {\n\tmt, err := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(msgName))\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error encode input\")\n\t}\n\n\tmsgType := reflect.TypeOf(mt.Zero().Interface())\n\n\tif msgType == nil {\n\t\treturn errors.Errorf(\"message of type %s unknown\", msgType)\n\t}\n\tmsg := reflect.New(msgType.Elem()).Interface().(proto.Message)\n\n\terr = protolator.DeepUnmarshalJSON(input, msg)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error decoding input\")\n\t}\n\n\tif msg == nil {\n\t\treturn errors.New(\"error marshaling: proto: Marshal called with nil\")\n\t}\n\tout, err := proto.Marshal(msg)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error marshaling\")\n\t}\n\n\t_, err = output.Write(out)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error writing output\")\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":125,"sourceCodeEnd":161,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/cmd/configtxlator/main.go#L125-L161","documentation":"In `encodeProto` (cmd/configtxlator/main.go:143), `protolator.DeepUnmarshalJSON(input, msg)` failed to decode the JSON input file into the target proto message. The JSON either isn't valid JSON or doesn't match the schema/field types of the --type message. configtxlator wraps this as 'error decoding input'.","triggerScenarios":"Running `configtxlator proto_encode` with an input JSON that is syntactically invalid, empty, truncated, contains unknown fields (strict decoding), or whose field types don't match the --type message schema (e.g. passing an Envelope JSON while --type is common.Config).","commonSituations":"Hand-editing exported JSON and breaking its syntax; encoding with the wrong --type for the JSON content; exporting JSON from a different Fabric proto version; feeding a protobuf binary file instead of JSON.","solutions":["Validate the input file is well-formed JSON (run it through jq or a JSON linter).","Ensure --type matches the JSON content (e.g. common.Envelope JSON needs --type common.Envelope, not common.Config).","Remove unknown fields or re-export the JSON from the same Fabric version's configtxlator proto_decode.","Confirm you are passing the JSON file (not the .pb binary) to --input."],"exampleFix":"// before: type mismatch\n$ configtxlator proto_encode --type common.Config --input envelope.json --output out.pb\n// after: match type to content\n$ configtxlator proto_encode --type common.Envelope --input envelope.json --output out.pb","handlingStrategy":"validation","validationCode":"// Validate JSON parses and matches the expected type before encoding\nimport json\npayload = json.load(open(input_path))\nif type_arg == 'common.Envelope' and 'signature' not in payload:\n    raise SystemExit('input looks like an Envelope but --type is not common.Envelope')\nif type_arg == 'common.Config' and 'channel_group' not in payload:\n    raise SystemExit('input does not look like common.Config')","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"configtxlator\", \"proto_encode\", \"--type\", t, \"--input\", f, \"--output\", o).CombinedOutput()\nif err != nil && strings.Contains(string(out), \"error decoding input\") {\n\treturn fmt.Errorf(\"JSON in %s does not match %s; run: jq . %s\", f, t, f)\n}","preventionTips":["Always produce input JSON via `configtxlator proto_decode` instead of hand-writing it.","Match --type to the JSON you decoded from — never mix Envelope JSON with common.Config.","Run `jq . input.json` to catch syntax errors before encoding.","Avoid editing unknown fields; delete only what you intend to change."],"tags":["hyperledger-fabric","configtxlator","json","decoding"],"backgroundTag":"json-decode-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}