{"record":{"id":"5268f344d35a0e78","repo":"hyperledger/fabric","slug":"error-marshaling-proposalresponse-proto-marshal","errorCode":null,"errorMessage":"error marshaling ProposalResponse: proto: Marshal called with nil","messagePattern":"error marshaling ProposalResponse: proto: Marshal called with nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":174,"sourceCode":"\t}\n\teventBytes, err := proto.Marshal(event)\n\treturn eventBytes, errors.Wrap(err, \"error marshaling ChaincodeEvent\")\n}\n\n// GetBytesChaincodeActionPayload get the bytes of ChaincodeActionPayload from\n// the message\nfunc GetBytesChaincodeActionPayload(cap *peer.ChaincodeActionPayload) ([]byte, error) {\n\tif cap == nil {\n\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\")","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L156-L192","documentation":"GetBytesProposalResponse serializes a *peer.ProposalResponse. A nil pointer cannot be passed to proto.Marshal, so the function returns this explicit 'proto: Marshal called with nil' error. It protects callers in the transaction-assembly path from opaque proto failures.","triggerScenarios":"Calling protoutil.GetBytesProposalResponse(nil), or passing an element of a ProposalResponse slice that is nil (e.g. a peer in the endorsement set returned no response).","commonSituations":"Collecting endorsements where one peer's response slot is empty due to a failed/timeout endorsement, or test code (TestProposalResponse) exercising the nil path.","solutions":["Nil-check each ProposalResponse before serialization and drop/log the missing endorsement.","Validate the endorsement collection step so no nil entries enter the slice.","Retry the endorsement against the failed peer before assembling the transaction.","In tests, build &peer.ProposalResponse{...} rather than a nil pointer."],"exampleFix":"// before\nprBytes, err := protoutil.GetBytesProposalResponse(pr)\n// after\nif pr == nil {\n    return nil, errors.New(\"endorsement missing ProposalResponse from peer\")\n}\nprBytes, err := protoutil.GetBytesProposalResponse(pr)","handlingStrategy":"validation","validationCode":"for i, pr := range proposalResponses {\n    if pr == nil {\n        return nil, fmt.Errorf(\"proposalResponses[%d] is nil: missing endorsement\", i)\n    }\n}","typeGuard":"func hasProposalResponse(pr *peer.ProposalResponse) bool {\n    return pr != nil\n}","tryCatchPattern":"prBytes, err := protoutil.GetBytesProposalResponse(pr)\nif err != nil {\n    return nil, errors.Wrap(err, \"ProposalResponse serialization failed\")\n}","preventionTips":["Filter nil entries from endorsement collections before transaction assembly.","Check each peer's endorsement result for errors/timeouts before using its response.","Retry failed endorsements rather than leaving nil slots in the slice."],"tags":["grpc","protobuf","nil-pointer","endorsement","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"}