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

code generated by the trpc create command reports an error #42

Open
tyanxie opened this issue May 17, 2024 · 9 comments
Open

code generated by the trpc create command reports an error #42

tyanxie opened this issue May 17, 2024 · 9 comments

Comments

@tyanxie
Copy link

tyanxie commented May 17, 2024

What version of trpc-cmdline are you using?

v1.0.9

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE='on'
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/tyanxie/Library/Caches/go-build'
GOENV='/Users/tyanxie/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/tyanxie/Projects/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/tyanxie/Projects/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/Users/tyanxie/DevTools/gos/go1.22.2'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/tyanxie/DevTools/gos/go1.22.2/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='clang'
CXX='clang++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/z8/0hqvm5bx7058y4tghsqv9q2h0000gn/T/go-build492708761=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

download the docs/helloworld/helloworld.proto file and run trpc create -p helloworld.proto -o .

What did you expect to see?

  1. the test cases in the generated hello_world_service_test.go file can be executed directly without modification, even if it makes no sense
  2. the generated stub code helloworld_mock.go reported no error

What did you see instead?

  1. two errors in the hello_world_service_test.go file
image
  1. before executing go mod tidy, the helloworld_mock.go file reported an error
image

My thoughts 1

I used the trpc setup command to install the mockgen command.

It looks like the installed mockgen is github.com/golang/mock/mockgen, so the stub code helloworld_mock.go generated using the trpc create command introduced github.com/golang/mock library.

However, the hello_world_service_test.go and go.mod files tend to import the go.uber.org/mock library, thus causing some of the errors. (In addition, I noticed that the manual installation of dependencies in the README.md document also tends to install go.uber.org/mock)

Regarding this issue, I think two points should be carefully considered:

  1. It is necessary to check and unify the dependence on the mock library.
  2. Do you need to try to be compatible with both mockgen libraries? Although go.uber.org/mock is now more recommended, some users also install github.com/golang/mock/mockgen locally.

My thoughts 2

For the gomock.InOrder function used in line 28 of the file hello_world_service_test.go, the parameter it accepts is ...any, but it seems that the parameter currently passed in is ...*gomock.Call, That's why there is such an error.

In short, I expect that the test code can be run directly after executing the trpc create command without modifying anything.

@WineChord
Copy link
Contributor

I have updated the binaries to https://github.com/uber-go/mock/tree/main/gomock. You can delete the dependencies and run trpc setup again.

@tyanxie
Copy link
Author

tyanxie commented May 17, 2024

I have updated the binaries to https://github.com/uber-go/mock/tree/main/gomock. You can delete the dependencies and run trpc setup again.

thanks, this solves part of the issue

@WineChord
Copy link
Contributor

@tyanxie Hi, do you find any problem with the new binaries such as trpc-group/trpc-go#180?

@tyanxie
Copy link
Author

tyanxie commented May 21, 2024

@tyanxie Hi, do you find any problem with the new binaries such as trpc-group/trpc-go#180?

@WineChord Sorry, I didn't have any problems using the latest mockgen you updated.

Then i extracted the core message: fork/exec /Users/guoqizhou/go/go1.21.2/bin/go: no such file or directory

From this sentence, mockgen did not find the file /Users/guoqizhou/go/go1.21.2/bin/go. I think troubleshooting may be start on check from this aspect: whether the go program is installed correctly.

@WineChord
Copy link
Contributor

@tyanxie I reckon it is because my path information is built into the binary, which is causing the trouble. But when I marked out the required go/bin path, I was still not able to reproduce the user's error. Very curious.

@tyanxie
Copy link
Author

tyanxie commented May 21, 2024

@WineChord I can't reproduce the user issue either. I traced that when some errors occur, mockgen will execute the parsePackage function, which will be called the Import function in go/build, then calls the Context.importGo method, which will use GOROOT/bin/go to execute the go list command, and finaly occur error.

Maybe the essential problem is that GOROOT is set incorrectly, but no matter what, we may not be able to continue troubleshooting now, unless the owner of that issue gives more detailed information, such as go env, .proto files, etc.

@WineChord
Copy link
Contributor

@tyanxie Yes, it seems that here the code produces the wrong path with some wrong GOROOT.

@WineChord
Copy link
Contributor

@tyanxie Some latest finding: trpc-group/trpc-go#180 (comment)

@tyanxie
Copy link
Author

tyanxie commented May 31, 2024

@tyanxie Some latest finding: trpc-group/trpc-go#180 (comment)

Perfect!👍

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

2 participants