mirror of
https://github.com/go-micro/go-micro.git
synced 2025-06-12 22:07:47 +02:00
fixing string field contains invalid UTF-8 issue (#2164)
This commit is contained in:
@ -14,9 +14,8 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"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/broker"
|
||||||
|
"github.com/asim/go-micro/v3/cmd"
|
||||||
"github.com/asim/go-micro/v3/errors"
|
"github.com/asim/go-micro/v3/errors"
|
||||||
"github.com/asim/go-micro/v3/logger"
|
"github.com/asim/go-micro/v3/logger"
|
||||||
meta "github.com/asim/go-micro/v3/metadata"
|
meta "github.com/asim/go-micro/v3/metadata"
|
||||||
@ -26,6 +25,7 @@ import (
|
|||||||
"github.com/asim/go-micro/v3/util/backoff"
|
"github.com/asim/go-micro/v3/util/backoff"
|
||||||
mgrpc "github.com/asim/go-micro/v3/util/grpc"
|
mgrpc "github.com/asim/go-micro/v3/util/grpc"
|
||||||
mnet "github.com/asim/go-micro/v3/util/net"
|
mnet "github.com/asim/go-micro/v3/util/net"
|
||||||
|
"github.com/golang/protobuf/proto"
|
||||||
"golang.org/x/net/netutil"
|
"golang.org/x/net/netutil"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"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
|
// micro.Error now proto based and we can attach it to grpc status
|
||||||
statusCode = microError(verr)
|
statusCode = microError(verr)
|
||||||
statusDesc = verr.Error()
|
statusDesc = verr.Error()
|
||||||
|
verr.Detail = strings.ToValidUTF8(verr.Detail, "")
|
||||||
errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr)
|
errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
// micro.Error now proto based and we can attach it to grpc status
|
||||||
statusCode = microError(verr)
|
statusCode = microError(verr)
|
||||||
statusDesc = verr.Error()
|
statusDesc = verr.Error()
|
||||||
|
verr.Detail = strings.ToValidUTF8(verr.Detail, "")
|
||||||
errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr)
|
errStatus, err = status.New(statusCode, statusDesc).WithDetails(verr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -56,7 +56,7 @@ func (s *testServer) CallPcreInvalid(ctx context.Context, req *pb.Request, rsp *
|
|||||||
// TestHello implements helloworld.GreeterServer
|
// TestHello implements helloworld.GreeterServer
|
||||||
func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
|
func (s *testServer) Call(ctx context.Context, req *pb.Request, rsp *pb.Response) error {
|
||||||
if req.Name == "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
|
rsp.Msg = "Hello " + req.Name
|
||||||
@ -196,7 +196,7 @@ func TestGRPCServer(t *testing.T) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
t.Fatalf("invalid error received %#+v\n", st.Details()[0])
|
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)
|
t.Fatalf("invalid error received %#+v\n", verr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user