]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: replace 'directory .' with 'current directory' in some errors
authorMichael Matloob <matloob@golang.org>
Wed, 16 Nov 2022 18:28:32 +0000 (13:28 -0500)
committerMichael Matloob <matloob@golang.org>
Fri, 18 Nov 2022 18:09:53 +0000 (18:09 +0000)
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>
src/cmd/go/internal/modload/load.go
src/cmd/go/testdata/script/mod_fs_patterns.txt
src/cmd/go/testdata/script/work_module_not_in_go_work.txt

index d92e2ba7101d14438fe0f03979887dc1bb26bfc0..e4f6a953205990160db2aca5fb0e5e5a06b7f67e 100644 (file)
@@ -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
 }
index 276d04e538e0b10945b74c317f55076040d36e81..c834ce851e04d616b7fb9a42e178db65f7a1cdbb 100644 (file)
@@ -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
index 5d3e64ce80748c61ca6137738a0107c66e6300ed..074bac5d6839c8aed93285c0a6041d96f10aa990 100644 (file)
@@ -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