mirror of
https://github.com/go-micro/go-micro.git
synced 2024-11-24 08:02:32 +02:00
fixing string field contains invalid UTF-8 issue (#2164)
This commit is contained in:
parent
9e9157d878
commit
8c9c7a5927
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user