From: Michael Matloob Date: Wed, 16 Nov 2022 18:28:32 +0000 (-0500) Subject: cmd/go: replace 'directory .' with 'current directory' in some errors X-Git-Tag: go1.20rc1~161 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=fd00c14bf1b7057ae301ec82b82efa0ec5ccc9b4;p=gostls13.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 TryBot-Result: Gopher Robot Run-TryBot: Bryan Mills Reviewed-by: Joedian Reid --- diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index d92e2ba710..e4f6a95320 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -603,13 +603,17 @@ func resolveLocalPackage(ctx context.Context, dir string, rs *Requirements) (str pkg := pathInModuleCache(ctx, absDir, rs) if pkg == "" { + dirstr := fmt.Sprintf("directory %s", base.ShortPath(absDir)) + if dirstr == "directory ." { + dirstr = "current directory" + } 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:\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 } diff --git a/src/cmd/go/testdata/script/mod_fs_patterns.txt b/src/cmd/go/testdata/script/mod_fs_patterns.txt index 276d04e538..c834ce851e 100644 --- a/src/cmd/go/testdata/script/mod_fs_patterns.txt +++ b/src/cmd/go/testdata/script/mod_fs_patterns.txt @@ -51,11 +51,11 @@ stdout '^at$' # a package path. cd ../badat/bad@ ! go list . -stderr 'directory . outside main module or its selected dependencies' +stderr 'current directory outside main module or its selected dependencies' ! 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/... -stderr 'directory . outside main module or its selected dependencies' +stderr 'current directory outside main module or its selected dependencies' -- x/go.mod -- module m 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 5d3e64ce80..074bac5d68 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 @@ -14,7 +14,11 @@ stderr 'directory a[\\/]c is contained in a module that is not one of the worksp 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 \.\.' +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 1.18 @@ -32,3 +36,5 @@ package main module example.com/b go 1.18 +-- foo.go -- +package foo