From 76afc4f3cdb6b0c83304e80f4d2780cdca808ce8 Mon Sep 17 00:00:00 2001 From: Ben Wells Date: Sat, 23 May 2020 17:18:41 +0100 Subject: [PATCH] Remove usage of deprecated grpc.Errorf API --- .../internal/proto/examplepb/echo_service.pb.gw.go | 8 ++++---- protoc-gen-grpc-gateway/descriptor/types.go | 2 +- runtime/BUILD.bazel | 1 - runtime/handler_test.go | 11 +++++------ 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/examples/internal/proto/examplepb/echo_service.pb.gw.go b/examples/internal/proto/examplepb/echo_service.pb.gw.go index 0f492600bc2..2353a417db1 100644 --- a/examples/internal/proto/examplepb/echo_service.pb.gw.go +++ b/examples/internal/proto/examplepb/echo_service.pb.gw.go @@ -242,7 +242,7 @@ func request_EchoService_Echo_2(ctx context.Context, marshaler runtime.Marshaler if protoReq.Code == nil { protoReq.Code = &SimpleMessage_Lang{} } else if _, ok := protoReq.Code.(*SimpleMessage_Lang); !ok { - return nil, metadata, grpc.Errorf(codes.InvalidArgument, "expect type: *SimpleMessage_Lang, but: %t\n", protoReq.Code) + return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *SimpleMessage_Lang, but: %t\n", protoReq.Code) } protoReq.Code.(*SimpleMessage_Lang).Lang, err = runtime.String(val) @@ -303,7 +303,7 @@ func local_request_EchoService_Echo_2(ctx context.Context, marshaler runtime.Mar if protoReq.Code == nil { protoReq.Code = &SimpleMessage_Lang{} } else if _, ok := protoReq.Code.(*SimpleMessage_Lang); !ok { - return nil, metadata, grpc.Errorf(codes.InvalidArgument, "expect type: *SimpleMessage_Lang, but: %t\n", protoReq.Code) + return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *SimpleMessage_Lang, but: %t\n", protoReq.Code) } protoReq.Code.(*SimpleMessage_Lang).Lang, err = runtime.String(val) @@ -357,7 +357,7 @@ func request_EchoService_Echo_3(ctx context.Context, marshaler runtime.Marshaler if protoReq.Code == nil { protoReq.Code = &SimpleMessage_LineNum{} } else if _, ok := protoReq.Code.(*SimpleMessage_LineNum); !ok { - return nil, metadata, grpc.Errorf(codes.InvalidArgument, "expect type: *SimpleMessage_LineNum, but: %t\n", protoReq.Code) + return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *SimpleMessage_LineNum, but: %t\n", protoReq.Code) } protoReq.Code.(*SimpleMessage_LineNum).LineNum, err = runtime.Int64(val) @@ -418,7 +418,7 @@ func local_request_EchoService_Echo_3(ctx context.Context, marshaler runtime.Mar if protoReq.Code == nil { protoReq.Code = &SimpleMessage_LineNum{} } else if _, ok := protoReq.Code.(*SimpleMessage_LineNum); !ok { - return nil, metadata, grpc.Errorf(codes.InvalidArgument, "expect type: *SimpleMessage_LineNum, but: %t\n", protoReq.Code) + return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *SimpleMessage_LineNum, but: %t\n", protoReq.Code) } protoReq.Code.(*SimpleMessage_LineNum).LineNum, err = runtime.Int64(val) diff --git a/protoc-gen-grpc-gateway/descriptor/types.go b/protoc-gen-grpc-gateway/descriptor/types.go index ab6edbeb370..3238ec18928 100644 --- a/protoc-gen-grpc-gateway/descriptor/types.go +++ b/protoc-gen-grpc-gateway/descriptor/types.go @@ -323,7 +323,7 @@ func (p FieldPath) AssignableExpr(msgExpr string) string { s := `if %s == nil { %s =&%s{} } else if _, ok := %s.(*%s); !ok { - return nil, metadata, grpc.Errorf(codes.InvalidArgument, "expect type: *%s, but: %%t\n",%s) + return nil, metadata, status.Errorf(codes.InvalidArgument, "expect type: *%s, but: %%t\n",%s) }` preparations = append(preparations, fmt.Sprintf(s, components, components, oneofFieldName, components, oneofFieldName, oneofFieldName, components)) diff --git a/runtime/BUILD.bazel b/runtime/BUILD.bazel index c4d18f624a8..58b72b9cf75 100644 --- a/runtime/BUILD.bazel +++ b/runtime/BUILD.bazel @@ -78,7 +78,6 @@ go_test( "@io_bazel_rules_go//proto/wkt:struct_go_proto", "@io_bazel_rules_go//proto/wkt:timestamp_go_proto", "@io_bazel_rules_go//proto/wkt:wrappers_go_proto", - "@org_golang_google_grpc//:go_default_library", "@org_golang_google_grpc//codes:go_default_library", "@org_golang_google_grpc//metadata:go_default_library", "@org_golang_google_grpc//status:go_default_library", diff --git a/runtime/handler_test.go b/runtime/handler_test.go index ea369add028..570602d4c08 100644 --- a/runtime/handler_test.go +++ b/runtime/handler_test.go @@ -12,7 +12,6 @@ import ( "github.com/grpc-ecosystem/grpc-gateway/internal" "github.com/grpc-ecosystem/grpc-gateway/runtime" pb "github.com/grpc-ecosystem/grpc-gateway/runtime/internal/examplepb" - "google.golang.org/grpc" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" ) @@ -49,13 +48,13 @@ func TestForwardResponseStream(t *testing.T) { statusCode: http.StatusOK, }, { name: "error", - msgs: []msg{{nil, grpc.Errorf(codes.OutOfRange, "400")}}, + msgs: []msg{{nil, status.Errorf(codes.OutOfRange, "400")}}, statusCode: http.StatusBadRequest, }, { name: "stream_error", msgs: []msg{ {&pb.SimpleMessage{Id: "One"}, nil}, - {nil, grpc.Errorf(codes.OutOfRange, "400")}, + {nil, status.Errorf(codes.OutOfRange, "400")}, }, statusCode: http.StatusOK, }, { @@ -70,7 +69,7 @@ func TestForwardResponseStream(t *testing.T) { name: "response body stream error case", msgs: []msg{ {fakeReponseBodyWrapper{&pb.SimpleMessage{Id: "One"}}, nil}, - {nil, grpc.Errorf(codes.OutOfRange, "400")}, + {nil, status.Errorf(codes.OutOfRange, "400")}, }, responseBody: true, statusCode: http.StatusOK, @@ -203,13 +202,13 @@ func TestForwardResponseStreamCustomMarshaler(t *testing.T) { statusCode: http.StatusOK, }, { name: "error", - msgs: []msg{{nil, grpc.Errorf(codes.OutOfRange, "400")}}, + msgs: []msg{{nil, status.Errorf(codes.OutOfRange, "400")}}, statusCode: http.StatusBadRequest, }, { name: "stream_error", msgs: []msg{ {&pb.SimpleMessage{Id: "One"}, nil}, - {nil, grpc.Errorf(codes.OutOfRange, "400")}, + {nil, status.Errorf(codes.OutOfRange, "400")}, }, statusCode: http.StatusOK, }}