cmd/go: add helpful suggestion to run go mod tidy
with -e
in cases where it fails looking for missing source packages
#49292
Labels
GoCommand
cmd/go
modules
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?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/orgo.sum
got pooched and any attempts to rungo
commands resulted in an error instructing me to rungo 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". Runninggo mod tidy
gave me a number of such errors:Note that all of these imports are part of the local repository, and belong to the
module
prefix defined ingo.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 rungo 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 ofgo 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 withgo
? Otherwise it's quite difficult to reason about this seemingly impossible chicken-and-egg scenario.The text was updated successfully, but these errors were encountered: