diff --git a/plugins/server/grpc/grpc.go b/plugins/server/grpc/grpc.go index cad47078..24fdb91a 100644 --- a/plugins/server/grpc/grpc.go +++ b/plugins/server/grpc/grpc.go @@ -14,9 +14,8 @@ import ( "sync" "time" - "github.com/golang/protobuf/proto" - "github.com/asim/go-micro/v3/cmd" "github.com/asim/go-micro/v3/broker" + "github.com/asim/go-micro/v3/cmd" "github.com/asim/go-micro/v3/errors" "github.com/asim/go-micro/v3/logger" meta "github.com/asim/go-micro/v3/metadata" @@ -26,6 +25,7 @@ import ( "github.com/asim/go-micro/v3/util/backoff" mgrpc "github.com/asim/go-micro/v3/util/grpc" mnet "github.com/asim/go-micro/v3/util/net" + "github.com/golang/protobuf/proto" "golang.org/x/net/netutil" "google.golang.org/grpc" @@ -405,6 +405,7 @@ func (g *grpcServer) processRequest(stream grpc.ServerStream, service *service, // micro.Error now proto based and we can attach it to grpc status statusCode = microError(verr) statusDesc = verr.Error() + verr.Detail = strings.ToValidUTF8(verr.Detail, "") errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr) if err != nil { return err @@ -477,6 +478,7 @@ func (g *grpcServer) processStream(stream grpc.ServerStream, service *service, m // micro.Error now proto based and we can attach it to grpc status statusCode = microError(verr) statusDesc = verr.Error() + verr.Detail = strings.ToValidUTF8(verr.Detail, "") errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr) if err != nil { return err diff --git a/plugins/server/grpc/grpc_test.go b/plugins/server/grpc/grpc_test.go index 32d90e59..50fc3e31 100644 --- a/plugins/server/grpc/grpc_test.go +++ b/plugins/server/grpc/grpc_test.go @@ -56,7 +56,7 @@ func (s *testServer) CallPcreInvalid(ctx context.Context, req *pb.Request, rsp * // TestHello implements helloworld.GreeterServer func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error { if req.Name == "Error" { - return &errors.Error{Id: "1", Code: 99, Detail: "detail"} + return &errors.Error{Id: "1", Code: 99, Detail: "detail\xc5"} } rsp.Msg = "Hello " + req.Name @@ -196,7 +196,7 @@ func TestGRPCServer(t *testing.T) { if !ok { t.Fatalf("invalid error received %#+v\n", st.Details()[0]) } - if verr.Code != 99 && verr.Id != "1" && verr.Detail != "detail" { + if verr.Code != 99 || verr.Id != "1" || verr.Detail != "detail" { t.Fatalf("invalid error received %#+v\n", verr) } }