Repository: go
Issue: cmd/go: add helpful suggestion to run `go mod tidy` with `-e` in cases where it fails looking for missing source packages
Labels: NeedsInvestigation,GoCommand,modules

<!--
Please answer these questions before submitting your issue. Thanks!
For questions please use one of our forums: https://github.com/golang/go/wiki/Questions
-->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.17.1 darwin/arm64
</pre>

### 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](https://entgo.io/) 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.