]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/load: treat packages with errors as potentially main packages
authorBryan C. Mills <bcmills@google.com>
Tue, 27 Apr 2021 07:01:08 +0000 (03:01 -0400)
committerBryan C. Mills <bcmills@google.com>
Tue, 27 Apr 2021 18:34:55 +0000 (18:34 +0000)
If a package declares 'package main' but for some reason we fail to
read its name (for example, due to a permission or checksum error),
we may be tempted to drop the package from the output of
mainPackagesOnly. However, that leads to a confusing
"no packages loaded from …" error message.

Instead, we will treat packages with errors as potentially-main
packages, and print the error. At least if we print why the package is
broken, the user will understand that the weird behavior is due to the
broken package rather than, say, a typo on their part in the command
arguments.

Updates #42088
For #36460

Change-Id: I033c0d28ac7d105d9df3ba5f9327e5c0c2a29954
Reviewed-on: https://go-review.googlesource.com/c/go/+/314050
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/load/pkg.go

index acba2323087eb8a930c16a69687226bbeae51521..c1e3eaa0f3896520824d24aec6af92ad4f7dbe4d 100644 (file)
@@ -2563,7 +2563,7 @@ func mainPackagesOnly(pkgs []*Package, patterns []string) []*Package {
        mainCount := make([]int, len(patterns))
        nonMainCount := make([]int, len(patterns))
        for _, pkg := range pkgs {
-               if pkg.Name == "main" {
+               if pkg.Name == "main" || (pkg.Incomplete && pkg.Name == "") {
                        matchedPkgs = append(matchedPkgs, pkg)
                        for i := range patterns {
                                if matchers[i] != nil && matchers[i](pkg.ImportPath) {