mirror of https://github.com/golang/go.git
cmd/go: replace 'directory .' with 'current directory' in some errors
To make the error clearer Fixes #56697 Change-Id: Idfb5e8704d1bfc64bd0a09d5b553086d9ba5ac33 Reviewed-on: https://go-review.googlesource.com/c/go/+/451295 Reviewed-by: Bryan Mills <bcmills@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Bryan Mills <bcmills@google.com> Reviewed-by: Joedian Reid <joedian@golang.org>
This commit is contained in:
parent
b2faff18ce
commit
fd00c14bf1
|
|
@ -603,13 +603,17 @@ func resolveLocalPackage(ctx context.Context, dir string, rs *Requirements) (str
|
||||||
|
|
||||||
pkg := pathInModuleCache(ctx, absDir, rs)
|
pkg := pathInModuleCache(ctx, absDir, rs)
|
||||||
if pkg == "" {
|
if pkg == "" {
|
||||||
|
dirstr := fmt.Sprintf("directory %s", base.ShortPath(absDir))
|
||||||
|
if dirstr == "directory ." {
|
||||||
|
dirstr = "current directory"
|
||||||
|
}
|
||||||
if inWorkspaceMode() {
|
if inWorkspaceMode() {
|
||||||
if mr := findModuleRoot(absDir); mr != "" {
|
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:\n\tgo work use %s", base.ShortPath(absDir), base.ShortPath(mr))
|
return "", fmt.Errorf("%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", dirstr, base.ShortPath(mr))
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("directory %s outside modules listed in go.work or their selected dependencies", base.ShortPath(absDir))
|
return "", fmt.Errorf("%s outside modules listed in go.work or their selected dependencies", dirstr)
|
||||||
}
|
}
|
||||||
return "", fmt.Errorf("directory %s outside main module or its selected dependencies", base.ShortPath(absDir))
|
return "", fmt.Errorf("%s outside main module or its selected dependencies", dirstr)
|
||||||
}
|
}
|
||||||
return pkg, nil
|
return pkg, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,11 @@ stdout '^at$'
|
||||||
# a package path.
|
# a package path.
|
||||||
cd ../badat/bad@
|
cd ../badat/bad@
|
||||||
! go list .
|
! go list .
|
||||||
stderr 'directory . outside main module or its selected dependencies'
|
stderr 'current directory outside main module or its selected dependencies'
|
||||||
! go list $PWD
|
! go list $PWD
|
||||||
stderr 'directory . outside main module or its selected dependencies'
|
stderr 'current directory outside main module or its selected dependencies'
|
||||||
! go list $PWD/...
|
! go list $PWD/...
|
||||||
stderr 'directory . outside main module or its selected dependencies'
|
stderr 'current directory outside main module or its selected dependencies'
|
||||||
|
|
||||||
-- x/go.mod --
|
-- x/go.mod --
|
||||||
module m
|
module m
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,11 @@ stderr 'directory a[\\/]c is contained in a module that is not one of the worksp
|
||||||
|
|
||||||
cd a/c
|
cd a/c
|
||||||
! go run .
|
! 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 \.\.'
|
stderr 'current 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 \.\.'
|
||||||
|
|
||||||
|
cd ../..
|
||||||
|
! go run .
|
||||||
|
stderr 'current directory outside modules listed in go.work or their selected dependencies'
|
||||||
|
|
||||||
-- go.work --
|
-- go.work --
|
||||||
go 1.18
|
go 1.18
|
||||||
|
|
@ -32,3 +36,5 @@ package main
|
||||||
module example.com/b
|
module example.com/b
|
||||||
|
|
||||||
go 1.18
|
go 1.18
|
||||||
|
-- foo.go --
|
||||||
|
package foo
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue