{"record":{"id":"2aefb6ab8de58269","repo":"hyperledger/fabric","slug":"error-marshaling","errorCode":null,"errorMessage":"error marshaling","messagePattern":"error marshaling","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/configtxlator/main.go","lineNumber":151,"sourceCode":"\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\nfunc decodeProto(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","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/cmd/configtxlator/main.go#L133-L169","documentation":"In `encodeProto` (cmd/configtxlator/main.go:151), `proto.Marshal(msg)` failed while serializing the decoded message to protobuf binary. This indicates the message content violates proto serialization constraints (e.g. required content missing, invalid enum, oversized/invalid nested values). configtxlator wraps it as 'error marshaling'.","triggerScenarios":"Running `configtxlator proto_encode` where the JSON decodes into a message whose content fails proto.Marshal — e.g. invalid field values that pass JSON parsing but fail proto validation, or deeply inconsistent config content.","commonSituations":"Hand-crafted config JSON with out-of-range values (ports, policy rules); corrupted JSON round-trips mixing Fabric versions; fields containing invalid bytes or malformed nested messages.","solutions":["Read the wrapped inner proto error to find the offending field.","Fix invalid field values in the input JSON (ports in range, valid policy types, well-formed signatures).","Re-export the JSON via `configtxlator proto_decode` from a known-good .pb and re-apply only intended edits.","Confirm input/output Fabric proto versions are consistent."],"exampleFix":"// before (invalid value fails proto.Marshal)\n{ \"payload\": { \"header\": { \"channel_header\": { \"version\": -1 } } } }\n// after\n{ \"payload\": { \"header\": { \"channel_header\": { \"version\": 0 } } } }","handlingStrategy":"validation","validationCode":"// Sanity-check risky numeric fields before marshaling\ndef check_config(cfg):\n    for org in cfg.get('channel_group', {}).get('groups', {}).values():\n        for o in org.get('groups', {}).values():\n            ap = o.get('values', {}).get('AnchorPeers', {})\n    # also validate enum fields are in range before encode\n    return True","typeGuard":null,"tryCatchPattern":"out, err := exec.Command(\"configtxlator\", \"proto_encode\", ...).CombinedOutput()\nif err != nil && strings.Contains(string(out), \"error marshaling\") {\n\treturn fmt.Errorf(\"content invalid for proto.Marshal; inspect wrapped proto error: %s\", out)\n}","preventionTips":["Edit only known fields in decoded JSON; keep everything else byte-identical to the proto_decode output.","Validate ports, versions, and enum values are in valid proto ranges.","Re-derive JSON from a known-good .pb after failed edits instead of incrementally patching.","Keep fabric proto versions consistent between decode and encode steps."],"tags":["hyperledger-fabric","configtxlator","protobuf","serialization"],"backgroundTag":"proto-marshal-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"}