Skip to content

Commit

Permalink
use FromError
Browse files Browse the repository at this point in the history
Signed-off-by: Kosuke Morimoto <[email protected]>
  • Loading branch information
kmrmt committed Oct 2, 2024
1 parent d6b6c8c commit 88152c3
Showing 1 changed file with 25 additions and 11 deletions.
36 changes: 25 additions & 11 deletions pkg/gateway/filter/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -1448,10 +1448,13 @@ func (s *server) Search(
}
res, err = s.gateway.Search(ctx, req, s.copts...)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to convert "+vald.SearchRPCName+" gRPC error response")

Check warning on line 1453 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L1451-L1453

Added lines #L1451 - L1453 were not covered by tests
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 1457 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L1457

Added line #L1457 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
Expand Down Expand Up @@ -1531,10 +1534,13 @@ func (s *server) SearchByID(
}()
res, err = s.gateway.SearchByID(ctx, req, s.copts...)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.SearchByIDRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to convert "+vald.SearchByIDRPCName+" gRPC error response")

Check warning on line 1539 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L1537-L1539

Added lines #L1537 - L1539 were not covered by tests
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 1543 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L1543

Added line #L1543 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
return nil, err
Expand Down Expand Up @@ -2196,11 +2202,13 @@ func (s *server) StreamLinearSearchByID(
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal,
"failed to parse "+vald.StreamLinearSearchRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to convert "+vald.StreamLinearSearchRPCName+" gRPC error response")

Check warning on line 2207 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L2205-L2207

Added lines #L2205 - L2207 were not covered by tests
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 2211 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L2211

Added line #L2211 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
log.Error(err)
Expand Down Expand Up @@ -3056,10 +3064,13 @@ func (s *server) StreamUpsert(stream vald.Upsert_StreamUpsertServer) (err error)
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.StreamUpsertRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to parse "+vald.StreamUpsertRPCName+" gRPC error response")

Check warning on line 3069 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L3067-L3069

Added lines #L3067 - L3069 were not covered by tests
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 3073 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L3073

Added line #L3073 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
log.Error(err)
Expand Down Expand Up @@ -3223,10 +3234,13 @@ func (s *server) StreamRemove(stream vald.Remove_StreamRemoveServer) (err error)
}, nil
})
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.StreamRemoveRPCName+" gRPC error response")
st, ok := status.FromError(err)
if !ok || st == nil {
st = status.New(codes.Internal, "failed to parse "+vald.StreamRemoveRPCName+" gRPC error response")

Check warning on line 3239 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L3237-L3239

Added lines #L3237 - L3239 were not covered by tests
}
if span != nil {
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 3243 in pkg/gateway/filter/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/filter/handler/grpc/handler.go#L3243

Added line #L3243 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
log.Error(err)
Expand Down

0 comments on commit 88152c3

Please sign in to comment.