mirror of
https://github.com/golang/go
synced 2024-09-15 22:20:06 +00:00
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>
This commit is contained in:
parent
bd1bff4e7a
commit
ea6cb02ae5
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue