diff options
| author | Bryan C. Mills <bcmills@google.com> | 2022-07-18 12:09:47 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2022-08-17 16:11:11 +0000 |
| commit | ea6cb02ae54fcf89026a2178720396f1277dd105 (patch) | |
| tree | 82b2d445839bd4a6a01e6f5255828a382e0f6e57 /src | |
| parent | bd1bff4e7aa1e417aaa617a7f10b1cff88a6e243 (diff) | |
| download | go-ea6cb02ae54fcf89026a2178720396f1277dd105.tar.xz | |
cmd/go: propagate match errors in 'go run'
Fixes #51604.
Change-Id: I3bc86652c62d2b329d9c2db5ea443d56cf17f8d1
Reviewed-on: https://go-review.googlesource.com/c/go/+/418094
Reviewed-by: Nooras Saba <saba@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Run-TryBot: Bryan Mills <bcmills@google.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/cmd/go/internal/load/pkg.go | 2 | ||||
| -rw-r--r-- | src/cmd/go/internal/modload/load.go | 2 | ||||
| -rw-r--r-- | src/cmd/go/testdata/script/work_module_not_in_go_work.txt | 11 |
3 files changed, 11 insertions, 4 deletions
diff --git a/src/cmd/go/internal/load/pkg.go b/src/cmd/go/internal/load/pkg.go index 2cd61b9dcb..19d02e8bd9 100644 --- a/src/cmd/go/internal/load/pkg.go +++ b/src/cmd/go/internal/load/pkg.go @@ -2915,7 +2915,7 @@ func mainPackagesOnly(pkgs []*Package, matches []*search.Match) []*Package { var mains []*Package for _, pkg := range pkgs { - if pkg.Name == "main" { + if pkg.Name == "main" || (pkg.Name == "" && pkg.Error != nil) { treatAsMain[pkg.ImportPath] = true mains = append(mains, pkg) continue diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index ba85dc2438..a36ac9c5bb 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -607,7 +607,7 @@ func resolveLocalPackage(ctx context.Context, dir string, rs *Requirements) (str if pkg == "" { if inWorkspaceMode() { if mr := findModuleRoot(absDir); mr != "" { - return "", fmt.Errorf("directory %s is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using go work use %s", base.ShortPath(absDir), base.ShortPath(mr)) + return "", fmt.Errorf("directory %s is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using:\n\tgo work use %s", base.ShortPath(absDir), base.ShortPath(mr)) } return "", fmt.Errorf("directory %s outside modules listed in go.work or their selected dependencies", base.ShortPath(absDir)) } diff --git a/src/cmd/go/testdata/script/work_module_not_in_go_work.txt b/src/cmd/go/testdata/script/work_module_not_in_go_work.txt index 9109b2de7f..5d3e64ce80 100644 --- a/src/cmd/go/testdata/script/work_module_not_in_go_work.txt +++ b/src/cmd/go/testdata/script/work_module_not_in_go_work.txt @@ -7,7 +7,14 @@ stderr 'pattern ./...: directory prefix . does not contain modules listed in go.work or their selected dependencies' ! go list ./a/c -stderr 'directory a[\\/]c is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using go work use a' +stderr 'directory a[\\/]c is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using:\n\tgo work use a' + +! go install ./a/c +stderr 'directory a[\\/]c is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using:\n\tgo work use a' + +cd a/c +! go run . +stderr 'directory . is contained in a module that is not one of the workspace modules listed in go.work. You can add the module to the workspace using:\n\tgo work use \.\.' -- go.work -- go 1.18 @@ -20,7 +27,7 @@ go 1.18 -- a/a.go -- package a -- a/c/c.go -- -package c +package main -- b/go.mod -- module example.com/b |
