From d08f5a5811f0f19e7981bc3f60a391e7d722a261 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 14:08:52 +0300 Subject: [PATCH 1/2] service: get status error even if it is wrapped --- service/meta.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/service/meta.go b/service/meta.go index abffdadd..c5d09f72 100644 --- a/service/meta.go +++ b/service/meta.go @@ -2,6 +2,7 @@ package service import ( "github.com/nspcc-dev/neofs-proto/internal" + "github.com/pkg/errors" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -101,7 +102,7 @@ func ProcessRequestTTL(req MetaHeader, cond ...TTLCondition) error { // check specific condition: if err := cond[i](ttl); err != nil { - if st, ok := status.FromError(err); ok { + if st, ok := status.FromError(errors.Cause(err)); ok { return st.Err() } From a893e389b0d9c2c58bc2d39e8691a1be5e85f256 Mon Sep 17 00:00:00 2001 From: Evgeniy Kulikov Date: Tue, 26 Nov 2019 14:09:23 +0300 Subject: [PATCH 2/2] service: test coverage for wrapped status errors --- service/meta_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/service/meta_test.go b/service/meta_test.go index 496ea519..e208dfe1 100644 --- a/service/meta_test.go +++ b/service/meta_test.go @@ -3,6 +3,7 @@ package service import ( "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/require" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -54,6 +55,18 @@ func TestMetaRequest(t *testing.T) { RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL}, handler: func(_ uint32) error { return status.Error(codes.NotFound, "not found") }, }, + { + msg: "not found", + code: codes.NotFound, + name: "custom wrapped status error", + RequestMetaHeader: RequestMetaHeader{TTL: SingleForwardingTTL}, + handler: func(_ uint32) error { + err := status.Error(codes.NotFound, "not found") + err = errors.Wrap(err, "some error context") + err = errors.Wrap(err, "another error context") + return err + }, + }, } for i := range tests {