Grpc-gateway: AnnotateIncomingContext not declared by package runtime

Created on 2 Sep 2019  路  4Comments  路  Source: grpc-ecosystem/grpc-gateway

Steps you follow to reproduce the error:

curl -sSL https://github.com/uber/prototool/releases/download/v1.8.0/prototool-$(shell uname -s)-$(shell uname -m) -o /usr/local/bin/prototool
chmod +x /usr/local/bin/prototool
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go

Compile code

What did you expect to happen instead:

It to compile correctly

What's your theory on why it isn't working:

proto/gen/go/service/front.pb.gw.go:73:24: AnnotateIncomingContext not declared by package runtime (typecheck)
        rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req)

There is a new commit that has AnnotateIncomingContext declared in the runtime package. Releasing a new version with that commit in should solve the problem

Most helpful comment

Hi @trelore. This is a consequence of using go get to install the generator while using a dependency management tool to version the runtime. The runtime package and generator must be using the same version. There are two ways to solve your issue:

  1. Version the generators, too.
    For example using deps required or go modules tool dependencies.
  2. Use master for both the generators and the runtime.

Speaking from experience with other users running into this problem though, I'm gonna make release 1.11.1.

All 4 comments

Hi @trelore. This is a consequence of using go get to install the generator while using a dependency management tool to version the runtime. The runtime package and generator must be using the same version. There are two ways to solve your issue:

  1. Version the generators, too.
    For example using deps required or go modules tool dependencies.
  2. Use master for both the generators and the runtime.

Speaking from experience with other users running into this problem though, I'm gonna make release 1.11.1.

@johanbrandhorst

I also met the same issue, can you clarify a little bit more on,

There are two ways to solve your issue:

  1. Version the generators, too.
    For example using deps required or go modules tool dependencies.
  2. Use master for both the generators and the runtime.

I'm using the commands provided from README to do the installation,

go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway
go get -u github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger
go get -u github.com/golang/protobuf/protoc-gen-go

I am sure the runtime and generators should be updated to date and align with each other right?

Hi Minghe,

Yeah so if you're using go modules you don't want to be using those commands, because they will all update independently and also update all downstream dependencies. What you want to do is add a tool dependency for github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway and github.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger and then just run

$ go install github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gatewaygithub.com/grpc-ecosystem/grpc-gateway/protoc-gen-swagger

It will use the versions from your go.mod file, which will be the same as the version of the runtime (which should also be tracked in your go.mod file, of course).

Does that help?

I ran into this issue, here was my fix. I checked my go.mod file and saw that I was running v1.9 for some reason. I manually changed the version number to the version installed to my gopath.

All fixed.

Was this page helpful?
0 / 5 - 0 ratings