{"record":{"id":"4fdc796c5f049f48","repo":"hyperledger/fabric","slug":"error-marshaling-header-proto-marshal-called-wit","errorCode":null,"errorMessage":"error marshaling Header: proto: Marshal called with nil","messagePattern":"error marshaling Header: proto: Marshal called with nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":183,"sourceCode":"\t\treturn nil, errors.New(\"error marshaling ChaincodeActionPayload: proto: Marshal called with nil\")\n\t}\n\tcapBytes, err := proto.Marshal(cap)\n\treturn capBytes, errors.Wrap(err, \"error marshaling ChaincodeActionPayload\")\n}\n\n// GetBytesProposalResponse gets proposal bytes response\nfunc GetBytesProposalResponse(pr *peer.ProposalResponse) ([]byte, error) {\n\tif pr == nil {\n\t\treturn nil, errors.New(\"error marshaling ProposalResponse: proto: Marshal called with nil\")\n\t}\n\trespBytes, err := proto.Marshal(pr)\n\treturn respBytes, errors.Wrap(err, \"error marshaling ProposalResponse\")\n}\n\n// GetBytesHeader get the bytes of Header from the message\nfunc GetBytesHeader(hdr *common.Header) ([]byte, error) {\n\tif hdr == nil {\n\t\treturn nil, errors.New(\"error marshaling Header: proto: Marshal called with nil\")\n\t}\n\tbytes, err := proto.Marshal(hdr)\n\treturn bytes, errors.Wrap(err, \"error marshaling Header\")\n}\n\n// GetBytesSignatureHeader get the bytes of SignatureHeader from the message\nfunc GetBytesSignatureHeader(hdr *common.SignatureHeader) ([]byte, error) {\n\tif hdr == nil {\n\t\treturn nil, errors.New(\"error marshaling SignatureHeader: proto: Marshal called with nil\")\n\t}\n\tbytes, err := proto.Marshal(hdr)\n\treturn bytes, errors.Wrap(err, \"error marshaling SignatureHeader\")\n}\n\n// GetBytesTransaction get the bytes of Transaction from the message\nfunc GetBytesTransaction(tx *peer.Transaction) ([]byte, error) {\n\tif tx == nil {\n\t\treturn nil, errors.New(\"error marshaling Transaction: proto: Marshal called with nil\")","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L165-L201","documentation":"GetBytesHeader serializes a *common.Header. Because proto.Marshal cannot accept a nil message, the function checks for nil and returns this explicit error instead. Headers carry channel/type/nonce info used in proposals and transactions.","triggerScenarios":"Calling protoutil.GetBytesHeader(nil), or passing a Header field from a Proposal that was never built (e.g. makeFailureResponse-style paths in TestProposal where hdr creation was skipped).","commonSituations":"Constructing proposals/transactions programmatically where the Header (channel header + signature header) assembly step failed or was skipped, or parsing malformed payloads from envelopes.","solutions":["Nil-check the *common.Header before calling GetBytesHeader.","Ensure the Header was built via protoutil.ChainHeaderTransaction/SigHeader construction helpers before serialization.","When extracting from an envelope/payload, verify the extraction step returned non-nil.","In tests, construct &common.Header{ChannelHeader: ..., SignatureHeader: ...} before invoking."],"exampleFix":"// before\nhdrBytes, err := protoutil.GetBytesHeader(hdr)\n// after\nif hdr == nil {\n    return nil, errors.New(\"proposal is missing Header\")\n}\nhdrBytes, err := protoutil.GetBytesHeader(hdr)","handlingStrategy":"validation","validationCode":"if hdr == nil {\n    return nil, errors.New(\"cannot serialize: common.Header is nil\")\n}","typeGuard":"func hasHeader(prop *peer.Proposal) bool {\n    return prop != nil && prop.Header != nil\n}","tryCatchPattern":"hdrBytes, err := protoutil.GetBytesHeader(hdr)\nif err != nil {\n    return nil, errors.Wrap(err, \"Header serialization failed\")\n}","preventionTips":["Build proposals with protoutil.CreateProposal/ChainHeader helpers so Header is always set.","Nil-check Header (and its ChannelHeader/SignatureHeader) right after extraction from envelopes.","In tests, seed headers via protoutil.MakeChannelHeader and MakeSignatureHeader."],"tags":["grpc","protobuf","nil-pointer","hyperledger-fabric"],"backgroundTag":"proto-marshal-nil-message","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"}