{"record":{"id":"b91d0173e2dce145","repo":"hyperledger/fabric","slug":"error-marshaling-response-proto-marshal-called-w","errorCode":null,"errorMessage":"error marshaling Response: proto: Marshal called with nil","messagePattern":"error marshaling Response: proto: Marshal called with nil","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":146,"sourceCode":"\t\tProposalHash: hash,\n\t}\n\tprpBytes, err := proto.Marshal(prp)\n\treturn prpBytes, errors.Wrap(err, \"error marshaling ProposalResponsePayload\")\n}\n\n// GetBytesChaincodeProposalPayload gets the chaincode proposal payload\nfunc GetBytesChaincodeProposalPayload(cpp *peer.ChaincodeProposalPayload) ([]byte, error) {\n\tif cpp == nil {\n\t\treturn nil, errors.New(\"error marshaling ChaincodeProposalPayload: proto: Marshal called with nil\")\n\t}\n\tcppBytes, err := proto.Marshal(cpp)\n\treturn cppBytes, errors.Wrap(err, \"error marshaling ChaincodeProposalPayload\")\n}\n\n// GetBytesResponse gets the bytes of Response\nfunc GetBytesResponse(res *peer.Response) ([]byte, error) {\n\tif res == nil {\n\t\treturn nil, errors.New(\"error marshaling Response: proto: Marshal called with nil\")\n\t}\n\tresBytes, err := proto.Marshal(res)\n\treturn resBytes, errors.Wrap(err, \"error marshaling Response\")\n}\n\n// GetBytesChaincodeEvent gets the bytes of ChaincodeEvent\nfunc GetBytesChaincodeEvent(event *peer.ChaincodeEvent) ([]byte, error) {\n\tif event == nil {\n\t\treturn nil, errors.New(\"error marshaling ChaincodeEvent: proto: Marshal called with nil\")\n\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 {","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L128-L164","documentation":"GetBytesResponse serializes a *peer.Response to bytes via proto.Marshal. This error is returned explicitly when the caller passes a nil Response pointer, because gogo/proto's Marshal panics or fails when called with a nil message. The library guards the nil case and returns a descriptive error instead of crashing.","triggerScenarios":"Calling protoutil.GetBytesResponse(nil), or passing a struct field like pResp.Response that was never assigned because the ProposalResponse failed to populate.","commonSituations":"Processing a peer proposal response where the chaincode returned no action, deserializing payloads from malformed or truncated transactions, or test harnesses (TestProposalResponse) exercising nil inputs.","solutions":["Check the *peer.Response for nil before calling GetBytesResponse.","If extracting from a ProposalResponse, verify that pResp.Response was populated (e.g. the proposal actually succeeded).","Return or propagate a descriptive error upstream instead of marshaling.","In tests, initialize a valid &peer.Response{} rather than a nil pointer."],"exampleFix":"// before\nresBytes, err := protoutil.GetBytesResponse(pResp.Response)\n// after\nif pResp == nil || pResp.Response == nil {\n    return nil, errors.New(\"proposal response missing Response payload\")\n}\nresBytes, err := protoutil.GetBytesResponse(pResp.Response)","handlingStrategy":"validation","validationCode":"if res == nil {\n    return nil, errors.New(\"cannot serialize: peer.Response is nil\")\n}","typeGuard":"func hasResponse(pResp *peer.ProposalResponse) bool {\n    return pResp != nil && pResp.Response != nil\n}","tryCatchPattern":"resBytes, err := protoutil.GetBytesResponse(res)\nif err != nil {\n    return fmt.Errorf(\"GetBytesResponse: %w\", err)\n}","preventionTips":["Always nil-check protobuf message pointers before passing them to protoutil GetBytes* helpers.","Validate the full ProposalResponse (payload, endorsement, response) before serialization.","In endorsement-collection loops, filter out nil entries immediately."],"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"}