utrack / clay

Proto-first minimal server platform for gRPС+REST+Swagger APIs
MIT License
290 stars 37 forks source link

panic reflect: call of reflect.Value.Type on zero Value when sending patch request. #72

Closed jbactad closed 4 years ago

jbactad commented 4 years ago

I tried setting up a patch request gateway base from grpc_gateway documentation here.

Basically, I'm using field_mask and I'm trying to use the built-in behavior of grpc_gateway so that the client of the endpoint don't need to set the field_mask manually.

here is the callstack:

http: panic serving [::1]:58216: reflect: call of reflect.Value.Type on zero Value
goroutine 73 [running]:
net/http.(*conn).serve.func1(0xc001242000)
        /usr/local/Cellar/go/1.13.4/libexec/src/net/http/server.go:1767 +0x139
panic(0x19ae0e0, 0xc000252d40)
        /usr/local/Cellar/go/1.13.4/libexec/src/runtime/panic.go:679 +0x1b2
reflect.Value.Type(0x0, 0x0, 0x0, 0x1a30300, 0x400)
        /usr/local/Cellar/go/1.13.4/libexec/src/reflect/value.go:1877 +0x166
github.com/golang/protobuf/jsonpb.(*Unmarshaler).unmarshalValue(0xc000252d00, 0x0, 0x0, 0x0, 0xc000039a60, 0x11, 0x20, 0x0, 0x100ebd8, 0x20)
        /Users/user/Workspace/go/pkg/mod/github.com/golang/protobuf@v1.3.2/jsonpb/jsonpb.go:720 +0x5d
github.com/golang/protobuf/jsonpb.(*Unmarshaler).UnmarshalNext(0xc000252d00, 0xc0011ac2c0, 0x1d54d00, 0x0, 0x0, 0x19a0101)
        /Users/user/Workspace/go/pkg/mod/github.com/golang/protobuf@v1.3.2/jsonpb/jsonpb.go:682 +0x166
github.com/grpc-ecosystem/grpc-gateway/runtime.decodeJSONPb(0xc0011ac2c0, 0x1acc1c0, 0x0, 0x1d6ef01, 0xc0011ac2c0)
        /Users/user/Workspace/go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.12.1/runtime/marshal_jsonpb.go:176 +0xa5
github.com/grpc-ecosystem/grpc-gateway/runtime.DecoderWrapper.Decode(0xc0011ac2c0, 0x1acc1c0, 0x0, 0x1d54d00, 0x0)
        /Users/user/Workspace/go/pkg/mod/github.com/grpc-ecosystem/grpc-gateway@v1.12.1/runtime/marshal_jsonpb.go:149 +0x3f
github.com/utrack/clay/v2/transport/httpruntime.MarshalerPbJSON.Unmarshal(0x23e5380, 0x23e53c0, 0x23e5400, 0x23e34e0, 0x73024d8, 0xc000559fc0, 0x1acc1c0, 0x0, 0x1d59800, 0x73024d8)
        /Users/user/Workspace/go/pkg/mod/github.com/utrack/clay/v2@v2.4.1/transport/httpruntime/mjson.go:59 +0x25f
github.com/org/project/pkg/transaction_service.glob..func11.1(0x1a6f620, 0xc0004100c0, 0xc00125b788, 0x100ebd8)
        /Users/user/Workspace/go/src/github.com/org/project/pkg/transaction_service/transaction.pb.goclay.go:802 +0x168
github.com/org/project/pkg/transaction_service._TransactionService_UpdateTransaction_Handler(0x1a1c9a0, 0xc000520030, 0x1d5c640, 0xc00029f680, 0xc000276f20, 0xc000459590, 0x30, 0x30, 0x1a53f40, 0xc00125b8a0)
        /Users/user/Workspace/go/src/github.com/org/project/pkg/transaction_service/transaction.pb.go:1956 +0x53
github.com/org/project/pkg/transaction_service.(*TransactionServiceDesc).RegisterHTTP.func7(0x1d57b40, 0xc000410080, 0xc0001c6500)
        /Users/user/Workspace/go/src/github.com/org/project/pkg/transaction_service/transaction.pb.goclay.go:289 +0x102
net/http.HandlerFunc.ServeHTTP(...)

Any help would be appreciated. Thanks.

utrack commented 4 years ago

Hi! Sorry for the late reply - field_mask functionality was indeed untested; I'll fix the bug soon.

utrack commented 4 years ago

Found https://github.com/grpc-ecosystem/grpc-gateway/issues/1136 while digging for a quick solution using existing registry.

utrack commented 4 years ago

This exact panic is caused by a separate bug that didn't allow usage of nested bindings (i.e. body: "some.foo"), but automatic FieldMask still shouldn't work right now. Since it's a separate issue - I've split it to #80.