Skip to content

Commit 8e0023b

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/load: treat packages with errors as potentially main packages
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>
1 parent bd2175e commit 8e0023b

File tree

1 file changed

+1
-1
lines changed
  • src/cmd/go/internal/load

1 file changed

+1
-1
lines changed

src/cmd/go/internal/load/pkg.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,7 @@ func mainPackagesOnly(pkgs []*Package, patterns []string) []*Package {
25632563
mainCount := make([]int, len(patterns))
25642564
nonMainCount := make([]int, len(patterns))
25652565
for _, pkg := range pkgs {
2566-
if pkg.Name == "main" {
2566+
if pkg.Name == "main" || (pkg.Incomplete && pkg.Name == "") {
25672567
matchedPkgs = append(matchedPkgs, pkg)
25682568
for i := range patterns {
25692569
if matchers[i] != nil && matchers[i](pkg.ImportPath) {

0 commit comments

Comments
 (0)