Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Protovalidate interceptor cleanup, Go version bump #721

Merged
merged 5 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
protovalidate: return gRPC status-compatible error
  • Loading branch information
ash2k committed Aug 16, 2024
commit 69beab3f3f143b75d8d1235a18ee82e9f9e58fb3
2 changes: 1 addition & 1 deletion interceptors/protovalidate/protovalidate.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (w *wrappedServerStream) RecvMsg(m interface{}) error {
func validateMsg(m interface{}, validator *protovalidate.Validator, opts *options) error {
msg, ok := m.(proto.Message)
if !ok {
return errors.New("unsupported message type")
return status.Errorf(codes.Internal, "unsupported message type: %T", m)
}
if opts.shouldIgnoreMessage(msg.ProtoReflect().Descriptor().FullName()) {
return nil
Expand Down
4 changes: 2 additions & 2 deletions interceptors/protovalidate/protovalidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestUnaryServerInterceptor(t *testing.T) {

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

interceptor = protovalidate_middleware.UnaryServerInterceptor(validator,
Expand Down