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

Can't generate code with last version #384

Closed
nlamirault opened this issue May 11, 2017 · 13 comments
Closed

Can't generate code with last version #384

nlamirault opened this issue May 11, 2017 · 13 comments

Comments

@nlamirault
Copy link

hi
i try to update my code to last version (1.2.2):

$ protoc -I/usr/local/include -I. -I${GOPATH}/src -I../vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis --go_out=plugins=grpc:. *.proto
google/api/annotations.proto: File not found.
cmdb.proto: Import "google/api/annotations.proto" was not found or had errors.

Dependencies are :

$ govendor list +vendor |grep grpc
 v  github.com/grpc-ecosystem/go-grpc-middleware
 v  github.com/grpc-ecosystem/go-grpc-middleware/util/metautils
 v  github.com/grpc-ecosystem/go-grpc-prometheus                           v1.1    v1.1
 v  github.com/grpc-ecosystem/grpc-gateway/runtime                         v1.2.2  v1.2.2
 v  github.com/grpc-ecosystem/grpc-gateway/runtime/internal                v1.2.2  v1.2.2
 v  github.com/grpc-ecosystem/grpc-gateway/utilities                       v1.2.2  v1.2.2
 v  github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc
 v  github.com/mwitkow/go-grpc-middleware
 v  github.com/mwitkow/go-grpc-middleware/auth
 v  google.golang.org/grpc                                                 v1.3.0  v1.3.0
 v  google.golang.org/grpc/codes                                           v1.3.0  v1.3.0
 v  google.golang.org/grpc/credentials                                     v1.3.0  v1.3.0
 v  google.golang.org/grpc/grpclb/grpc_lb_v1                               v1.3.0  v1.3.0
 v  google.golang.org/grpc/grpclog                                         v1.3.0  v1.3.0
 v  google.golang.org/grpc/health                                          v1.3.0  v1.3.0
 v  google.golang.org/grpc/health/grpc_health_v1                           v1.3.0  v1.3.0
 v  google.golang.org/grpc/internal                                        v1.3.0  v1.3.0
 v  google.golang.org/grpc/keepalive                                       v1.3.0  v1.3.0
 v  google.golang.org/grpc/metadata                                        v1.3.0  v1.3.0
 v  google.golang.org/grpc/naming                                          v1.3.0  v1.3.0
 v  google.golang.org/grpc/peer                                            v1.3.0  v1.3.0
 v  google.golang.org/grpc/stats                                           v1.3.0  v1.3.0
 v  google.golang.org/grpc/status                                          v1.3.0  v1.3.0
 v  google.golang.org/grpc/tap                                             v1.3.0  v1.3.0
 v  google.golang.org/grpc/transport                                       v1.3.0  v1.3.0

I don't find any annotations.proto :

$ ls vendor/github.com/grpc-ecosystem/grpc-gateway/third_party/googleapis/
LICENSE  README.grpc-gateway
$ find . -name "annotations.proto"
$

I try to fetch external dependencies :

$ govendor fetch google.golang.org/genproto/googleapis/api/annotations
$ ls vendor/google.golang.org/genproto/googleapis/api/annotations/
annotations.pb.go  http.pb.go

I find this question on Stackoverflow : strange to copy annotations.proto file ?

Do you any idea ? Thanks

@nlamirault
Copy link
Author

nlamirault commented May 11, 2017

Using this dependency :

$ govendor fetch github.com/googleapis/googleapis/google/api

And these commands, it works :

$ protoc -I/usr/local/include -I. -I${GOPATH}/src -I../vendor/github.com/googleapis/googleapis --go_out=plugins=grpc:. *.proto
$ protoc -I/usr/local/include -I. -I$GOPATH/src -I../vendor/github.com/googleapis/googleapis --grpc-gateway_out=logtostderr=true:. cmdb.proto
$ protoc -I/usr/local/include -I. -I$GOPATH/src -I../vendor/github.com/googleapis/googleapis --swagger_out=logtostderr=true:. cmdb.proto

but build of the project failed :

pb/cmdb.pb.gw.go:149: too many arguments in call to runtime.AnnotateContext
pb/cmdb.pb.gw.go:151: too many arguments in call to runtime.HTTPError
pb/cmdb.pb.gw.go:156: too many arguments in call to runtime.HTTPError
pb/cmdb.pb.gw.go:160: too many arguments in call to forward_PlatformService_List_0
pb/cmdb.pb.gw.go:177: too many arguments in call to runtime.AnnotateContext
pb/cmdb.pb.gw.go:179: too many arguments in call to runtime.HTTPError
pb/cmdb.pb.gw.go:184: too many arguments in call to runtime.HTTPError
pb/cmdb.pb.gw.go:188: too many arguments in call to forward_PlatformService_Create_0
pb/cmdb.pb.gw.go:205: too many arguments in call to runtime.AnnotateContext
pb/cmdb.pb.gw.go:207: too many arguments in call to runtime.HTTPError
pb/cmdb.pb.gw.go:207: too many errors

I don't really undersant how generated code use Master and not Version 1.2.2

@tamalsaha
Copy link
Collaborator

pb/cmdb.pb.gw.go:149: too many arguments in call to runtime.AnnotateContext

This tells me that your *.gw.go file is generated using gateway from master branch. The generated file structure was changed in #336 . Regenerate the *.gw.go using gateway from 1.2.2 . This should be fixed.

@nlamirault
Copy link
Author

nlamirault commented May 11, 2017

Yes.
But i use grpc-gateway 1.2.2 in my vendor directory.

$ grep -R AnnotateContext vendor/github.com/grpc-ecosystem/grpc-gateway/
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context.go:AnnotateContext adds context information such as metadata from the request.
vendor/github.com/grpc-ecosystem/grpc-gateway/runtime/context.go:func AnnotateContext(ctx context.Context, req *http.Request) (context.Context, error) {

$ find  $GOPATH -name grpc-gateway
/home/vagrant/Apps/golang/src/gitlab.sys.op.mbs/diablo/vendor/github.com/grpc-ecosystem/grpc-gateway

$ protoc --version
libprotoc 3.3.0

@tamalsaha
Copy link
Collaborator

If you use grpc-gateway 1.2.2, then you need to generate the *.gw.go files using grpc-gateway 1.2.2

@nlamirault
Copy link
Author

nlamirault commented May 11, 2017

OK. I installed protoc-gen-grpc-gateway and protoc-gen-swagger like that :

$ 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

This is the error.
How install a specific version of this binaries ?

@tmc
Copy link
Collaborator

tmc commented May 11, 2017

@nlamirault can we consider this issue resolved?

perhaps these common gotchas could go into a wiki page?

@ewang
Copy link

ewang commented May 11, 2017

@nlamirault If you want to install from your vendor dir, you can do:

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

@nlamirault
Copy link
Author

Thanks. It works fine now.

@nlamirault
Copy link
Author

It could be helpful to provides binaries into a release files ?

@yuzheng21
Copy link

yuzheng21 commented Nov 7, 2017

Hi, I debugged this all the afternoon. I found that in the release v1.2.2, it doesn't include the commit from @tamalsaha #336

func AnnotateContext(ctx context.Context, req *http.Request) (context.Context, error) {

but in the template.go, it generates code with wrong number of parameters
rctx, err := runtime.AnnotateContext(ctx, req)

this is why I keep getting too many arguments in call to runtime.AnnotateContext, even though I use the latest version v1.2.2

@achew22
Copy link
Collaborator

achew22 commented Nov 18, 2017

Can you try this again with v1.3.0? If you have any more issues, please open a new issue

@cappuccino5
Copy link

I also encountered this problem, I have installed the Google/API/annotations. The proto, but still errors, specific solutions is, please?
$ protoc --go_out=protoc-gen-grpc --grpc-ruby_out=:. *.proto google/api/annotations.proto: File not found. api.proto: Import "google/api/annotations.proto" was not found or had errors.

@grpc-ecosystem grpc-ecosystem locked as resolved and limited conversation to collaborators Apr 28, 2019
@achew22
Copy link
Collaborator

achew22 commented Apr 28, 2019

@cappuccino5, could you either file a new issue with more details or go to the slack channel and work it out there? Thanks!

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

No branches or pull requests

7 participants