Merge pull request #596 from enisoc/errorf
Don't treat StatusDesc() as a format string.
This commit is contained in:
2
call.go
2
call.go
@ -185,6 +185,6 @@ func Invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli
|
|||||||
if lastErr != nil {
|
if lastErr != nil {
|
||||||
return toRPCErr(lastErr)
|
return toRPCErr(lastErr)
|
||||||
}
|
}
|
||||||
return Errorf(stream.StatusCode(), stream.StatusDesc())
|
return Errorf(stream.StatusCode(), "%s", stream.StatusDesc())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
21
call_test.go
21
call_test.go
@ -52,6 +52,7 @@ import (
|
|||||||
var (
|
var (
|
||||||
expectedRequest = "ping"
|
expectedRequest = "ping"
|
||||||
expectedResponse = "pong"
|
expectedResponse = "pong"
|
||||||
|
weirdError = "format verbs: %v%s"
|
||||||
sizeLargeErr = 1024 * 1024
|
sizeLargeErr = 1024 * 1024
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -95,6 +96,10 @@ func (h *testStreamHandler) handleStream(t *testing.T, s *transport.Stream) {
|
|||||||
t.Errorf("Failed to unmarshal the received message: %v", err)
|
t.Errorf("Failed to unmarshal the received message: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if v == "weird error" {
|
||||||
|
h.t.WriteStatus(s, codes.Internal, weirdError)
|
||||||
|
return
|
||||||
|
}
|
||||||
if v != expectedRequest {
|
if v != expectedRequest {
|
||||||
h.t.WriteStatus(s, codes.Internal, strings.Repeat("A", sizeLargeErr))
|
h.t.WriteStatus(s, codes.Internal, strings.Repeat("A", sizeLargeErr))
|
||||||
return
|
return
|
||||||
@ -223,3 +228,19 @@ func TestInvokeLargeErr(t *testing.T) {
|
|||||||
cc.Close()
|
cc.Close()
|
||||||
server.stop()
|
server.stop()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestInvokeErrorSpecialChars checks that error messages don't get mangled.
|
||||||
|
func TestInvokeErrorSpecialChars(t *testing.T) {
|
||||||
|
server, cc := setUp(t, 0, math.MaxUint32)
|
||||||
|
var reply string
|
||||||
|
req := "weird error"
|
||||||
|
err := Invoke(context.Background(), "/foo/bar", &req, &reply, cc)
|
||||||
|
if _, ok := err.(rpcError); !ok {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) receives non rpc error.")
|
||||||
|
}
|
||||||
|
if got, want := ErrorDesc(err), weirdError; got != want {
|
||||||
|
t.Fatalf("grpc.Invoke(_, _, _, _, _) error = %q, want %q", got, want)
|
||||||
|
}
|
||||||
|
cc.Close()
|
||||||
|
server.stop()
|
||||||
|
}
|
||||||
|
@ -257,7 +257,7 @@ func (cs *clientStream) RecvMsg(m interface{}) (err error) {
|
|||||||
cs.finish(err)
|
cs.finish(err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return Errorf(cs.s.StatusCode(), cs.s.StatusDesc())
|
return Errorf(cs.s.StatusCode(), "%s", cs.s.StatusDesc())
|
||||||
}
|
}
|
||||||
return toRPCErr(err)
|
return toRPCErr(err)
|
||||||
}
|
}
|
||||||
@ -269,7 +269,7 @@ func (cs *clientStream) RecvMsg(m interface{}) (err error) {
|
|||||||
// Returns io.EOF to indicate the end of the stream.
|
// Returns io.EOF to indicate the end of the stream.
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return Errorf(cs.s.StatusCode(), cs.s.StatusDesc())
|
return Errorf(cs.s.StatusCode(), "%s", cs.s.StatusDesc())
|
||||||
}
|
}
|
||||||
return toRPCErr(err)
|
return toRPCErr(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user