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

affected/package: mockgen更新有点随意 #180

Closed
forrestlinfeng opened this issue May 21, 2024 · 6 comments
Closed

affected/package: mockgen更新有点随意 #180

forrestlinfeng opened this issue May 21, 2024 · 6 comments

Comments

@forrestlinfeng
Copy link

What version of tRPC-Go are you using?

v0.0.1

trpc create遇到这个问题

trpc create err:exit status 1, reason:Execution err: running plugin mockgen, err: go mock mockgen err: cmd exec err: exit status 1, msg:2024/05/21 11:01:16 Loading input failed: makephoto.trpc.go:44:2: could not parse package trpc.group/trpc-go/trpc-go/server: go/build: go list trpc.group/trpc-go/trpc-go/server: fork/exec /Users/guoqizhou/go/go1.21.2/bin/go: no such file or directory , if the error is caused by 'go mod tidy' or 'mockgen', you may try adding '--nogomod' flag to use the outer go.mod of your project, or you can use '--mock=false' to disable go mod tidy and mockgen completely, if you are very curious, here's the explanation: Most of the errors are basically caused by the mockgen tool. Before executing mockgen, it requires running go mod tidy, which in turn needs a valid go.mod file. However, this go.mod file can have various issues, especially when your project already has an existing go.mod file. Therefore, using the '--nogomod' flag to disable the generation of a new go.mod file can solve the problem, or using the '--mock=false' flag can resolve the issue even more effectively (but there won't be any mock files generated :( ). Please run "trpc -h" or "trpc create -h" (or "trpc {some-other-subcommand} -h") for help messages.

@WineChord
Copy link
Contributor

Looks like the binary of mockgen is broken. I will update a new one.

@WineChord
Copy link
Contributor

@forrestlinfeng Didn't reproduce, which os are you using? Windows?

@WineChord
Copy link
Contributor

I have tried the new binary on Linux and macOS and didn't reproduce the error message.

@forrestlinfeng
Copy link
Author

forrestlinfeng commented May 30, 2024 via email

@WineChord
Copy link
Contributor

@forrestlinfeng Can you give detailed go env and steps to reproduce? As per discussion, we are unable to find the root cause given the information provided thus far.

@WineChord
Copy link
Contributor

@forrestlinfeng I think I have figured out the root cause:

image

The go src code here. Quoted as:

// Default is the default Context for builds.
// It uses the GOARCH, GOOS, GOROOT, and GOPATH environment variables
// if set, or else the compiled code's GOARCH, GOOS, and GOROOT.
var Default Context = defaultContext()

So, the newly compiled mockgen binary contains my GOROOT information. If users do not have go env GOROOT or system variable GOROOT set, go build/go list will use the GOROOT information compiled inside the go binary.

Quick fix:

export GOROOT="$(dirname "$(dirname "$(which go)")")"

But I am still curious about on what occasion the GOROOT will not be set by default? And why there wasn't any error message previously (maybe the previous compiled GOROOT information coincides with the user's local environment)?

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

3 participants