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

cmd/go: add helpful suggestion to run go mod tidy with -e in cases where it fails looking for missing source packages #49292

Open
Qix- opened this issue Nov 2, 2021 · 1 comment

Comments

@Qix-
Copy link

@Qix- Qix- commented Nov 2, 2021

What version of Go are you using (go version)?

$ go version
go version go1.17.1 darwin/arm64

Does this issue reproduce with the latest release?

Yes.

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

MacOS, arm64 (really not relevant here)


Somehow, my god.mod and/or go.sum got pooched and any attempts to run go commands resulted in an error instructing me to run go mod tidy.

However, I had just run a git clean -dffx (as I do sometimes) which means all of my generated Ent code was gone, and thus some of the imports were "broken". Running go mod tidy gave me a number of such errors:

github.com/my-org/my-repo/app imports
        github.com/my-org/my-repo/docs: no matching versions for query "latest"
github.com/my-org/my-repo/app imports
        github.com/my-org/my-repo/ent/migrate: no matching versions for query "latest"
github.com/my-org/my-repo/app/driver/ent imports
        github.com/my-org/my-repo/ent/chatroom: no matching versions for query "latest"
github.com/my-org/my-repo/app/driver/ent imports
        github.com/my-org/my-repo/ent/consent: no matching versions for query "latest"
github.com/my-org/my-repo/app/driver/ent imports
        github.com/my-org/my-repo/ent/enttest: no matching versions for query "latest"

Note that all of these imports are part of the local repository, and belong to the module prefix defined in go.mod. It doesn't make a whole lot of sense that querying the remote would find any missing source code here, as clearly the local repository is missing stuff and thus the remote might be too. Also, I don't want Go pulling stuff from the remote of the same repository to try to "fix" missing modules in the same repository as I'm developing on it. It's just all-around weird behavior in my opinion, unless I'm missing something.

Anyway, no problem, I'll just run my generation script again to generate them. Except I can't, because it required go run ... to generate them - which, naturally, errored about needing to run go mod tidy first.

This chicken-and-egg scenario left me dead in the water for a few hours (over the course of a few days) and there was no 'prompt' or suggestion on how to fix this. Likewise, Google searches came up with errors in code, which I knew isn't the case (in the case the code has been generated correctly, the application builds/runs fine).

After futzing around a bit I found that go mod tidy has an -e option which skips such errors and leaves the module system in a "good" state - after which I was able to run my Ent generation step just fine, and verify that everything was okay with a 'bare' run of go mod tidy (without -e).

So to save others a few hours of potential headaches, would it be possible to suggest to the user in cases where the above errors occur that running go mod tidy with -e might help fix indeterminate states of the local repository in cases where the code must be generated with go? Otherwise it's quite difficult to reason about this seemingly impossible chicken-and-egg scenario.

@seankhliao seankhliao changed the title Add helpful suggestion to run go mod tidy with -e in cases where it fails looking for missing source packages cmd/go: add helpful suggestion to run go mod tidy with -e in cases where it fails looking for missing source packages Nov 2, 2021
@seankhliao
Copy link
Contributor

@seankhliao seankhliao commented Nov 2, 2021

Loading

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

Successfully merging a pull request may close this issue.

None yet
2 participants