Convert io.ErrUnexpectedEOF to a codes.Internal-marked status in toRPCerr. (#2228)

This is consistent with how io.ErrUnexpectedEOF is handled in a bunch of
other places (e.g. stream.go, server.go), and signals to
application-level code that the error is retryable.
This commit is contained in:
David Symonds
2018-07-19 07:09:07 +10:00
committed by dfawley
parent b534d2d20e
commit 5562178a52
3 changed files with 7 additions and 0 deletions

View File

@ -50,6 +50,9 @@ func toRPCErr(err error) error {
if err == nil || err == io.EOF {
return err
}
if err == io.ErrUnexpectedEOF {
return status.Error(codes.Internal, err.Error())
}
if _, ok := status.FromError(err); ok {
return err
}

View File

@ -51,6 +51,9 @@ func toRPCErr(err error) error {
if err == nil || err == io.EOF {
return err
}
if err == io.ErrUnexpectedEOF {
return status.Error(codes.Internal, err.Error())
}
if _, ok := status.FromError(err); ok {
return err
}

View File

@ -179,6 +179,7 @@ func TestToRPCErr(t *testing.T) {
}{
{transport.StreamError{Code: codes.Unknown, Desc: ""}, status.Error(codes.Unknown, "")},
{transport.ErrConnClosing, status.Error(codes.Unavailable, transport.ErrConnClosing.Desc)},
{io.ErrUnexpectedEOF, status.Error(codes.Internal, io.ErrUnexpectedEOF.Error())},
} {
err := toRPCErr(test.errIn)
if _, ok := status.FromError(err); !ok {