{"record":{"id":"86b4736f007acb47","repo":"hyperledger/fabric","slug":"error-marshaling-86b473","errorCode":null,"errorMessage":"error marshaling","messagePattern":"error marshaling","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/txutils.go","lineNumber":102,"sourceCode":") (*common.Envelope, error) {\n\tpayloadChannelHeader := MakeChannelHeader(txType, msgVersion, channelID, epoch)\n\tpayloadChannelHeader.TlsCertHash = tlsCertHash\n\tvar err error\n\tpayloadSignatureHeader := &common.SignatureHeader{}\n\n\tif signer != nil {\n\t\tpayloadSignatureHeader, err = NewSignatureHeader(signer)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tif !dataMsg.ProtoReflect().IsValid() {\n\t\treturn nil, errors.New(\"error marshaling: proto: Marshal called with nil\")\n\t}\n\tdata, err := proto.Marshal(dataMsg)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"error marshaling\")\n\t}\n\n\tpaylBytes := MarshalOrPanic(\n\t\t&common.Payload{\n\t\t\tHeader: MakePayloadHeader(payloadChannelHeader, payloadSignatureHeader),\n\t\t\tData:   data,\n\t\t},\n\t)\n\n\tvar sig []byte\n\tif signer != nil {\n\t\tsig, err = signer.Sign(paylBytes)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t}\n\n\tenv := &common.Envelope{","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/txutils.go#L84-L120","documentation":"This is the generic wrap of a proto.Marshal failure inside CreateSignedEnvelopeWithTLSBinding. The nil case is pre-checked (error 2311), so this fires when the message contains fields that cannot be serialized — e.g. required/invalid field values, oversized data, or nested messages in an inconsistent state — and proto.Marshal returns an error.","triggerScenarios":"Calling CreateSignedEnvelopeWithTLSBinding with a message whose serialization fails: invalid enum values, deep recursion/size limits exceeded, or a corrupt nested proto message.","commonSituations":"Encoding a message assembled from unchecked external input; protobuf runtime/library version mismatches between generated code and runtime; extremely large payloads exceeding size limits in constrained environments.","solutions":["Log and inspect the wrapped underlying proto error to identify the offending field","Validate the message fields (enums, nested messages) before marshaling","Regenerate protobuf Go code with a runtime version matching the dependency (google.golang.org/protobuf vs github.com/golang/protobuf)","Reduce payload size if limits are being exceeded"],"exampleFix":"// before\nenv, err := protoutil.CreateSignedEnvelopeWithTLSBinding(t, chID, creator, msg, nil, 0)\n// after\nif err := msg.ProtoReflect().IsValid(); !err { return nil, errors.New(\"invalid msg\") }\nenv, err := protoutil.CreateSignedEnvelopeWithTLSBinding(t, chID, creator, msg, nil, 0)\nif err != nil {\n    return nil, fmt.Errorf(\"create envelope: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"func validateMarshalable(msg proto.Message) error {\n    if msg == nil || !msg.ProtoReflect().IsValid() {\n        return fmt.Errorf(\"nil/invalid message\")\n    }\n    if _, err := proto.Marshal(msg); err != nil {\n        return fmt.Errorf(\"pre-marshal check failed: %w\", err)\n    }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"data, err := protoutil.CreateSignedEnvelopeWithTLSBinding(t, chID, signer, msg, nil, 0)\nif err != nil {\n    return fmt.Errorf(\"marshal failed for %T: %w\", msg, err)\n}","preventionTips":["Validate enum values and nested messages before marshaling","Keep generated proto code and the protobuf runtime version aligned","Avoid assembling messages from unvalidated external input"],"tags":["protobuf","marshal","hyperledger-fabric"],"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"}