Skip to content

Commit

Permalink
fix: add code comment and refactor multi crud error handling
Browse files Browse the repository at this point in the history
Signed-off-by: hlts2 <[email protected]>
  • Loading branch information
hlts2 committed Oct 1, 2024
1 parent 3ceb863 commit 51f4a0e
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions pkg/gateway/mirror/handler/grpc/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,7 @@ func (s *server) StreamSearch(stream vald.Search_StreamSearchServer) (err error)
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 394 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L393-L394

Added lines #L393 - L394 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Proto(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.SearchRPCName+" gRPC error response")

Check warning on line 397 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L396-L397

Added lines #L396 - L397 were not covered by tests
}
Expand Down Expand Up @@ -446,6 +447,7 @@ func (s *server) StreamSearchByID(stream vald.Search_StreamSearchByIDServer) (er
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 449 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L448-L449

Added lines #L448 - L449 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Proto(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.SearchByIDRPCName+" gRPC error response")

Check warning on line 452 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L451-L452

Added lines #L451 - L452 were not covered by tests
}
Expand Down Expand Up @@ -770,6 +772,7 @@ func (s *server) StreamLinearSearch(stream vald.Search_StreamLinearSearchServer)
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 774 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L773-L774

Added lines #L773 - L774 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Proto(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.LinearSearchRPCName+" gRPC error response")

Check warning on line 777 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L776-L777

Added lines #L776 - L777 were not covered by tests
}
Expand Down Expand Up @@ -829,6 +832,7 @@ func (s *server) StreamLinearSearchByID(
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 834 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L833-L834

Added lines #L833 - L834 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Proto(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.LinearSearchByIDRPCName+" gRPC error response")

Check warning on line 837 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L836-L837

Added lines #L836 - L837 were not covered by tests
}
Expand Down Expand Up @@ -1071,6 +1075,7 @@ func (s *server) handleInsert(
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Code(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.InsertRPCName+" gRPC error response")

Check warning on line 1080 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1079-L1080

Added lines #L1079 - L1080 were not covered by tests
}
Expand Down Expand Up @@ -1227,6 +1232,7 @@ func (s *server) handleInsertResult(
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Code(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.UpdateRPCName+" gRPC error response")

Check warning on line 1237 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1236-L1237

Added lines #L1236 - L1237 were not covered by tests
}
Expand Down Expand Up @@ -1423,6 +1429,7 @@ func (s *server) StreamInsert(stream vald.Insert_StreamInsertServer) (err error)
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 1431 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1430-L1431

Added lines #L1430 - L1431 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Proto(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.InsertRPCName+" gRPC error response")

Check warning on line 1434 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1433-L1434

Added lines #L1433 - L1434 were not covered by tests
}
Expand Down Expand Up @@ -1491,14 +1498,10 @@ func (s *server) MultiInsert(

loc, err := s.Insert(ctx, req)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.InsertRPCName+" gRPC error response",
&errdetails.RequestInfo{
RequestId: req.GetVector().GetId(),
ServingData: errdetails.Serialize(req),
})
if span != nil {
st, ok := status.FromError(err)
if ok && st != nil && st.Message() != "" && span != nil {

Check warning on line 1502 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1501-L1502

Added lines #L1501 - L1502 were not covered by tests
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 1504 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1504

Added line #L1504 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
emu.Lock()
Expand Down Expand Up @@ -1603,6 +1606,7 @@ func (s *server) handleUpdate(
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Code(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.UpdateRPCName+" gRPC error response")

Check warning on line 1611 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1610-L1611

Added lines #L1610 - L1611 were not covered by tests
}
Expand Down Expand Up @@ -1773,6 +1777,7 @@ func (s *server) handleUpdateResult(
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Code(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.InsertRPCName+" gRPC error response")

Check warning on line 1782 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1781-L1782

Added lines #L1781 - L1782 were not covered by tests
}
Expand Down Expand Up @@ -1983,6 +1988,7 @@ func (s *server) StreamUpdate(stream vald.Update_StreamUpdateServer) (err error)
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 1990 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1989-L1990

Added lines #L1989 - L1990 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Proto(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.UpdateRPCName+" gRPC error response")

Check warning on line 1993 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L1992-L1993

Added lines #L1992 - L1993 were not covered by tests
}
Expand Down Expand Up @@ -2051,14 +2057,10 @@ func (s *server) MultiUpdate(

loc, err := s.Update(ctx, req)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.UpdateRPCName+" gRPC error response",
&errdetails.RequestInfo{
RequestId: req.GetVector().GetId(),
ServingData: errdetails.Serialize(req),
})
if span != nil {
st, ok := status.FromError(err)
if ok && st != nil && st.Message() != "" && span != nil {

Check warning on line 2061 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2060-L2061

Added lines #L2060 - L2061 were not covered by tests
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 2063 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2063

Added line #L2063 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
emu.Lock()
Expand Down Expand Up @@ -2163,6 +2165,7 @@ func (s *server) handleUpsert(
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Code(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.UpsertRPCName+" gRPC error response")

Check warning on line 2170 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2169-L2170

Added lines #L2169 - L2170 were not covered by tests
}
Expand Down Expand Up @@ -2357,6 +2360,7 @@ func (s *server) StreamUpsert(stream vald.Upsert_StreamUpsertServer) (err error)
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 2362 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2361-L2362

Added lines #L2361 - L2362 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Proto(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.UpsertRPCName+" gRPC error response")

Check warning on line 2365 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2364-L2365

Added lines #L2364 - L2365 were not covered by tests
}
Expand Down Expand Up @@ -2425,14 +2429,10 @@ func (s *server) MultiUpsert(

loc, err := s.Upsert(ctx, req)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.UpsertRPCName+" gRPC error response",
&errdetails.RequestInfo{
RequestId: req.GetVector().GetId(),
ServingData: errdetails.Serialize(req),
})
if span != nil {
st, ok := status.FromError(err)
if ok && st != nil && st.Message() != "" && span != nil {

Check warning on line 2433 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2432-L2433

Added lines #L2432 - L2433 were not covered by tests
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 2435 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2435

Added line #L2435 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
emu.Lock()
Expand Down Expand Up @@ -2537,6 +2537,7 @@ func (s *server) handleRemove(
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Code(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.RemoveRPCName+" gRPC error response")

Check warning on line 2542 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2541-L2542

Added lines #L2541 - L2542 were not covered by tests
}
Expand Down Expand Up @@ -2728,6 +2729,7 @@ func (s *server) StreamRemove(stream vald.Remove_StreamRemoveServer) (err error)
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 2731 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2730-L2731

Added lines #L2730 - L2731 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Proto(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.RemoveRPCName+" gRPC error response")

Check warning on line 2734 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2733-L2734

Added lines #L2733 - L2734 were not covered by tests
}
Expand Down Expand Up @@ -2796,14 +2798,10 @@ func (s *server) MultiRemove(

loc, err := s.Remove(ctx, req)
if err != nil {
st, msg, err := status.ParseError(err, codes.Internal, "failed to parse "+vald.RemoveRPCName+" gRPC error response",
&errdetails.RequestInfo{
RequestId: req.GetId().GetId(),
ServingData: errdetails.Serialize(req),
})
if span != nil {
st, ok := status.FromError(err)
if ok && st != nil && st.Message() != "" && span != nil {

Check warning on line 2802 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2801-L2802

Added lines #L2801 - L2802 were not covered by tests
span.RecordError(err)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), msg)...)
span.SetAttributes(trace.FromGRPCStatus(st.Code(), st.Message())...)

Check warning on line 2804 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2804

Added line #L2804 was not covered by tests
span.SetStatus(trace.StatusError, err.Error())
}
emu.Lock()
Expand Down Expand Up @@ -2861,6 +2859,7 @@ func (s *server) RemoveByTimestamp(
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 2861 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2860-L2861

Added lines #L2860 - L2861 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Code(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.InsertRPCName+" gRPC error response")

Check warning on line 2864 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2863-L2864

Added lines #L2863 - L2864 were not covered by tests
}
Expand Down Expand Up @@ -2910,6 +2909,7 @@ func (s *server) handleRemoveByTimestamp(
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Code(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.RemoveByTimestampRPCName+" gRPC error response")

Check warning on line 2914 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L2913-L2914

Added lines #L2913 - L2914 were not covered by tests
}
Expand Down Expand Up @@ -3166,6 +3166,7 @@ func (s *server) StreamGetObject(stream vald.Object_StreamGetObjectServer) (err
if err != nil {
st, ok := status.FromError(err)
if !ok || st == nil || st.Message() == "" {

Check warning on line 3168 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L3167-L3168

Added lines #L3167 - L3168 were not covered by tests
// This condition is implemented just in case to prevent nil pointer errors when retrieving st.Proto(), although it is unlikely to match this condition.
log.Errorf("gRPC call returned not a gRPC status error: %v", err)
st = status.New(codes.Internal, "failed to parse "+vald.GetObjectRPCName+" gRPC error response")

Check warning on line 3171 in pkg/gateway/mirror/handler/grpc/handler.go

View check run for this annotation

Codecov / codecov/patch

pkg/gateway/mirror/handler/grpc/handler.go#L3170-L3171

Added lines #L3170 - L3171 were not covered by tests
}
Expand Down

0 comments on commit 51f4a0e

Please sign in to comment.