diff options
author | Bryan C. Mills <bcmills@google.com> | 2019-07-03 17:12:32 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2020-02-27 20:07:49 +0000 |
commit | c739bc487d94c0617b3e4454f29271d08d66613c (patch) | |
tree | f897d72180d0b69b12815256fc8231e5c30c6f92 /src/cmd/go/internal/modload/query.go | |
parent | 956f64888d650e870d03c533b47646cf911bc396 (diff) | |
download | go-c739bc487d94c0617b3e4454f29271d08d66613c.tar.gz go-c739bc487d94c0617b3e4454f29271d08d66613c.zip |
cmd/go/internal/modload: make PackageNotInModuleError reasonable for the Target module
Updates #28459
Updates #32917
Change-Id: Iced562cb7c2e0ac075d8345f1e4ad3b073842dcf
Reviewed-on: https://go-review.googlesource.com/c/go/+/185343
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Diffstat (limited to 'src/cmd/go/internal/modload/query.go')
-rw-r--r-- | src/cmd/go/internal/modload/query.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go index 031e45938a..cf0dd3ff6e 100644 --- a/src/cmd/go/internal/modload/query.go +++ b/src/cmd/go/internal/modload/query.go @@ -445,7 +445,11 @@ func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]Q candidateModules = modulePrefixesExcludingTarget(base) ) if len(candidateModules) == 0 { - return nil, fmt.Errorf("package %s is not in the main module (%s)", pattern, Target.Path) + return nil, &PackageNotInModuleError{ + Mod: Target, + Query: query, + Pattern: pattern, + } } err := modfetch.TryProxies(func(proxy string) error { @@ -541,7 +545,9 @@ func queryPrefixModules(candidateModules []string, queryModule func(path string) case nil: found = append(found, r.QueryResult) case *PackageNotInModuleError: - if noPackage == nil { + // Given the option, prefer to attribute “package not in module” + // to modules other than the main one. + if noPackage == nil || noPackage.Mod == Target { noPackage = rErr } case *NoMatchingVersionError: @@ -626,6 +632,13 @@ type PackageNotInModuleError struct { } func (e *PackageNotInModuleError) Error() string { + if e.Mod == Target { + if strings.Contains(e.Pattern, "...") { + return fmt.Sprintf("main module (%s) does not contain packages matching %s", Target.Path, e.Pattern) + } + return fmt.Sprintf("main module (%s) does not contain package %s", Target.Path, e.Pattern) + } + found := "" if r := e.Replacement; r.Path != "" { replacement := r.Path |