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

Panic: reflect: Elem of invalid type #755

Open
abaruchi opened this issue Jun 6, 2022 · 1 comment
Open

Panic: reflect: Elem of invalid type #755

abaruchi opened this issue Jun 6, 2022 · 1 comment

Comments

@abaruchi
Copy link

abaruchi commented Jun 6, 2022

Hi,

I'm using the following versions:

  • github.com/gogo/protobuf v1.3.2
  • github.com/golang/protobuf v1.4.3
  • go version 1.17.1
  • macOS Catalina 10.15.7

The .proto file:

message ServiceAttestation {
  string field1 = 1;
  string field2 = 2;
}

message ServiceAttestationRequest {
    repeated ServiceAttestation request = 1 [(gogoproto.nullable) = false];
}

The request (PUT) to the service was a json like this:

{
    "request": [
        {
            "field1": "some_string",
            "field2": "aother_string"
        }
    ]
}

Panic message:

2022/06/06 14:57:13 http: panic serving [::1]:64968: reflect: Elem of invalid type packagepb.ServiceAttestation
goroutine 148 [running]:
net/http.(*conn).serve.func1()
        GOROOT/src/net/http/server.go:1802 +0xb9
panic({0x27de9c0, 0xc003abc760})
        GOROOT/src/runtime/panic.go:1047 +0x266
reflect.(*rtype).Elem(0xc00013a7e0)
        GOROOT/src/reflect/type.go:954 +0x134
google.golang.org/protobuf/internal/impl.(*messageConverter).New(0xc00149a6b0)
        external/org_golang_google_protobuf/internal/impl/convert.go:462 +0x29
google.golang.org/protobuf/internal/impl.(*listReflect).NewElement(0x2a360e0)
        external/org_golang_google_protobuf/internal/impl/convert_list.go:134 +0x22
github.com/golang/protobuf/jsonpb.(*Unmarshaler).unmarshalValue(0x286e820, {{}, 0x2a360e0, 0xc0035e9230, 0x7}, {0xc0001a61e0, 0xea, 0xf0}, {0x2f01c20, 0xc0009262a0})
        external/com_github_golang_protobuf/jsonpb/decode.go:402 +0x6ef
github.com/golang/protobuf/jsonpb.(*Unmarshaler).unmarshalMessage(0xc003ab62b8, {0x2ef11b0, 0xc003abc740}, {0xc00062a800, 0x0, 0x100})
        external/com_github_golang_protobuf/jsonpb/decode.go:339 +0x1c8c
github.com/golang/protobuf/jsonpb.(*Unmarshaler).UnmarshalNext(0xc000189180, 0x2a53ac0, {0xc79e7c0, 0xc003abee80})
        external/com_github_golang_protobuf/jsonpb/decode.go:127 +0x14e
github.com/grpc-ecosystem/grpc-gateway/runtime.decodeJSONPb(0xfd, {0x2a53ac0, 0xc003abee80})
        external/com_github_grpc_ecosystem_grpc_gateway/runtime/marshal_jsonpb.go:176 +0x70
github.com/grpc-ecosystem/grpc-gateway/runtime.DecoderWrapper.Decode({0xc79e7a0}, {0x2a53ac0, 0xc003abee80})
        external/com_github_grpc_ecosystem_grpc_gateway/runtime/marshal_jsonpb.go:149 +0x25
gitlab.gs.com/sre/sre/slo-repo/proto/manualattestation.local_request_ManualAttestationService_Insert_0({0x2ea34b0, 0xc0035e91a0}, {0x2ec1f60, 0xc0014920f0}, {0x2e96a08, 0xc001492180}, 0xc0035e4f00, 0x16)
        bazel-out/darwin-fastbuild-ST-3891b650e255/bin/proto/manualattestation/manualattestationpb_go_proto_/gitlab.gs.com/sre/sre/slo-repo/proto/manualattestation/manualattestation.pb.gw.go:61 +0x112
gitlab.gs.com/sre/sre/slo-repo/proto/manualattestation.RegisterManualAttestationServiceHandlerServer.func1({0x2e962e8, 0xc0009922a0}, 0xc0035e4f00, 0xc000191680)

Thanks,

@abaruchi
Copy link
Author

abaruchi commented Jun 8, 2022

Additional information:

When removing the gogoproto.nullable option (therefore, the struct created is a list of pointers []*somestruct) the code worked. I'm not sure, but looks like this nullabe option is hitting a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant