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:
3
go16.go
3
go16.go
@ -50,6 +50,9 @@ func toRPCErr(err error) error {
|
|||||||
if err == nil || err == io.EOF {
|
if err == nil || err == io.EOF {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err == io.ErrUnexpectedEOF {
|
||||||
|
return status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
if _, ok := status.FromError(err); ok {
|
if _, ok := status.FromError(err); ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
3
go17.go
3
go17.go
@ -51,6 +51,9 @@ func toRPCErr(err error) error {
|
|||||||
if err == nil || err == io.EOF {
|
if err == nil || err == io.EOF {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if err == io.ErrUnexpectedEOF {
|
||||||
|
return status.Error(codes.Internal, err.Error())
|
||||||
|
}
|
||||||
if _, ok := status.FromError(err); ok {
|
if _, ok := status.FromError(err); ok {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -179,6 +179,7 @@ func TestToRPCErr(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{transport.StreamError{Code: codes.Unknown, Desc: ""}, status.Error(codes.Unknown, "")},
|
{transport.StreamError{Code: codes.Unknown, Desc: ""}, status.Error(codes.Unknown, "")},
|
||||||
{transport.ErrConnClosing, status.Error(codes.Unavailable, transport.ErrConnClosing.Desc)},
|
{transport.ErrConnClosing, status.Error(codes.Unavailable, transport.ErrConnClosing.Desc)},
|
||||||
|
{io.ErrUnexpectedEOF, status.Error(codes.Internal, io.ErrUnexpectedEOF.Error())},
|
||||||
} {
|
} {
|
||||||
err := toRPCErr(test.errIn)
|
err := toRPCErr(test.errIn)
|
||||||
if _, ok := status.FromError(err); !ok {
|
if _, ok := status.FromError(err); !ok {
|
||||||
|
Reference in New Issue
Block a user