{"record":{"id":"fa68628a3178aaa5","repo":"hyperledger/fabric","slug":"error-unmarshalling","errorCode":null,"errorMessage":"error unmarshalling","messagePattern":"error unmarshalling","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/configtxlator/main.go","lineNumber":182,"sourceCode":"\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\tin, err := io.ReadAll(input)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error reading input\")\n\t}\n\n\terr = proto.Unmarshal(in, msg)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error unmarshalling\")\n\t}\n\n\terr = protolator.DeepMarshalJSON(output, msg)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error encoding output\")\n\t}\n\n\treturn nil\n}\n\nfunc computeUpdt(original, updated, output *os.File, channelID string) error {\n\torigIn, err := io.ReadAll(original)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"error reading original config\")\n\t}\n\n\torigConf := &cb.Config{}\n\terr = proto.Unmarshal(origIn, origConf)","sourceCodeStart":164,"sourceCodeEnd":200,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/cmd/configtxlator/main.go#L164-L200","documentation":"proto.Unmarshal rejected the input bytes while decoding to the requested message type. \"error unmarshalling\" means the binary data is not a valid wire-format encoding of the --type message (truncated, corrupted, or actually a different message/encoding such as JSON).","triggerScenarios":"Feeding a JSON config back into decode (wrong direction), decoding with the wrong --type so fields don't line up, truncated file from a failed export, or base64-encoded bytes not decoded first.","commonSituations":"Swapping encode/decode flags in scripts, editing a .pb file by hand, pulling a partial block of a channel config, or decoding a ConfigUpdate payload as common.Config.","solutions":["Confirm input is binary proto, not JSON; use `encode` for JSON→pb and `decode` for pb→JSON","Validate bytes with `protoc --decode_raw < config.pb` to see actual wire content","Match the --type to what was originally encoded (common.Config vs common.ConfigUpdate)","Re-export the config from the ordering service if the file is truncated/corrupt"],"exampleFix":"// before\nconfigtxlator decode --input config.json --output config.pb --type common.Config\n// after\nconfigtxlator encode --input config.json --output config.pb --type common.Config","handlingStrategy":"validation","validationCode":"// sniff binary vs JSON before decode\nhead -c1 \"$INPUT\" | grep -q '{' && echo \"input is JSON; use encode, not decode\" && exit 1","typeGuard":null,"tryCatchPattern":"out, err := cmd.CombinedOutput()\nif err != nil && strings.Contains(string(out), \"error unmarshalling\") {\n    return fmt.Errorf(\"input is not valid binary proto for the given --type: %w\", err)\n}","preventionTips":["Pair encode/decode calls correctly in scripts","Never hand-edit .pb files; edit JSON and re-encode","Sanity-check with protoc --decode_raw when unsure"],"tags":["protobuf","unmarshal","configtxlator","fabric"],"backgroundTag":"protobuf-unmarshal-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"}