Skip to content

Commit 69beab3

Browse files
committed
protovalidate: return gRPC status-compatible error
1 parent 114989e commit 69beab3

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

interceptors/protovalidate/protovalidate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (w *wrappedServerStream) RecvMsg(m interface{}) error {
6868
func validateMsg(m interface{}, validator *protovalidate.Validator, opts *options) error {
6969
msg, ok := m.(proto.Message)
7070
if !ok {
71-
return errors.New("unsupported message type")
71+
return status.Errorf(codes.Internal, "unsupported message type: %T", m)
7272
}
7373
if opts.shouldIgnoreMessage(msg.ProtoReflect().Descriptor().FullName()) {
7474
return nil

interceptors/protovalidate/protovalidate_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ func TestUnaryServerInterceptor(t *testing.T) {
5353

5454
t.Run("not_protobuf", func(t *testing.T) {
5555
_, err = interceptor(context.Background(), "not protobuf", info, handler)
56-
assert.Error(t, err)
57-
assert.Equal(t, codes.Unknown, status.Code(err))
56+
assert.EqualError(t, err, "rpc error: code = Internal desc = unsupported message type: string")
57+
assert.Equal(t, codes.Internal, status.Code(err))
5858
})
5959

6060
interceptor = protovalidate_middleware.UnaryServerInterceptor(validator,

0 commit comments

Comments
 (0)