{"record":{"id":"bc91ebfd29553415","repo":"hyperledger/fabric","slug":"error-marshaling-response","errorCode":null,"errorMessage":"error marshaling Response","messagePattern":"error marshaling Response","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"protoutil/proputils.go","lineNumber":149,"sourceCode":"\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 {\n\t\treturn nil, errors.New(\"error marshaling ChaincodeActionPayload: proto: Marshal called with nil\")\n\t}\n\tcapBytes, err := proto.Marshal(cap)","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/protoutil/proputils.go#L131-L167","documentation":"This is the wrapped error from proto.Marshal inside GetBytesResponse: serialization of the *peer.Response failed for a reason other than a nil pointer. The library wraps the underlying proto error with errors.Wrap to add the 'error marshaling Response' context.","triggerScenarios":"proto.Marshal returns a non-nil err while serializing a non-nil *peer.Response — typically with gogo/proto this is rare and indicates a malformed message or reflection failure; the message alone is the wrapped context (check the cause via errors.Cause).","commonSituations":"Corrupted in-memory Response objects built by deserializing invalid bytes, codegen/runtime version mismatches between the generated peer package and the proto library, or unexpected field types set via unsafe casting.","solutions":["Unwrap with github.com/pkg/errors Cause()/Unwrap() to see the real proto error.","Verify the peer package and proto runtime versions are compatible (go.mod pinning).","Rebuild/obtain the Response from a fresh proto message instead of reusing deserialized bytes of unknown provenance.","If the pointer was actually nil, add the nil check shown for the 'Marshal called with nil' variant."],"exampleFix":"// before\nresBytes, err := protoutil.GetBytesResponse(res)\nif err != nil {\n    return err\n}\n// after\nresBytes, err := protoutil.GetBytesResponse(res)\nif err != nil {\n    return errors.Wrapf(errors.Cause(err), \"serializing peer.Response (res=%v)\", res)\n}","handlingStrategy":"try-catch","validationCode":"if res == nil {\n    return nil, errors.New(\"peer.Response is nil\")\n}","typeGuard":"func isSerializableResponse(res *peer.Response) bool {\n    return res != nil\n}","tryCatchPattern":"resBytes, err := protoutil.GetBytesResponse(res)\nif err != nil {\n    return errors.Wrap(errors.Cause(err), \"Response serialization failed\")\n}","preventionTips":["Log errors.Cause(err) to see the underlying proto failure, not just the wrapper.","Keep fabric-protos-go and gogo/protobuf versions aligned in go.mod.","Only serialize messages built through the generated proto API, not manual decoding."],"tags":["grpc","protobuf","serialization","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"}