diff options
author | Michael Matloob <matloob@golang.org> | 2022-04-12 15:17:18 -0400 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-04-21 18:22:57 +0000 |
commit | f95db21332118134973ba046c4f5d0e890e36066 (patch) | |
tree | 74027070d71b68f3dcbc8e8e597f1532ddcd57fc /src/cmd/go/internal/modload/load.go | |
parent | 5b32a6f1793bbac820bc70066cb8f569edcaa982 (diff) | |
download | go-f95db21332118134973ba046c4f5d0e890e36066.tar.gz go-f95db21332118134973ba046c4f5d0e890e36066.zip |
cmd/go: add a better error message when in a module outside workspace
When the user is trying to list or build a package in a module that's
outside of the workspace provide a more clear message hinting to the
user that they can add the module to the workspace using go work use.
Fixes #51604
Change-Id: I1202ecb2f22fd6351bfdec88ed613b8167687fb7
Reviewed-on: https://go-review.googlesource.com/c/go/+/400014
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Auto-Submit: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/load.go')
-rw-r--r-- | src/cmd/go/internal/modload/load.go | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/cmd/go/internal/modload/load.go b/src/cmd/go/internal/modload/load.go index e85a33dd50..7f1a88ffe7 100644 --- a/src/cmd/go/internal/modload/load.go +++ b/src/cmd/go/internal/modload/load.go @@ -605,11 +605,13 @@ func resolveLocalPackage(ctx context.Context, dir string, rs *Requirements) (str pkg := pathInModuleCache(ctx, absDir, rs) if pkg == "" { - scope := "main module or its selected dependencies" if inWorkspaceMode() { - scope = "modules listed in go.work or their selected dependencies" + 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 outside modules listed in go.work or their selected dependencies", base.ShortPath(absDir)) } - return "", fmt.Errorf("directory %s outside %s", base.ShortPath(absDir), scope) + return "", fmt.Errorf("directory %s outside main module or its selected dependencies", base.ShortPath(absDir)) } return pkg, nil } |