]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: propagate match errors in 'go run'
authorBryan C. Mills <bcmills@google.com>
Mon, 18 Jul 2022 16:09:47 +0000 (12:09 -0400)
committerGopher Robot <gobot@golang.org>
Wed, 17 Aug 2022 16:11:11 +0000 (16:11 +0000)
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>

src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/modload/load.go
src/cmd/go/testdata/script/work_module_not_in_go_work.txt

index 2cd61b9dcb09d62f4560cb1f1ded183ee713c4e8..19d02e8bd994886d69682af1a2b4c1b5f139f145 100644 (file)
@@ -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
index ba85dc2438cb6a9cdef573312a66c3c60c7980f8..a36ac9c5bb61040783e94599dd0d4e53a085f466 100644 (file)
@@ -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))
                }
index 9109b2de7f21c1ec29fade0e11fc3c249d2400de..5d3e64ce80748c61ca6137738a0107c66e6300ed 100644 (file)
@@ -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