diff options
author | Bryan C. Mills <bcmills@google.com> | 2019-09-05 12:45:15 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2019-09-25 16:33:28 +0000 |
commit | 8189a06190046cd69819ad1c6399943be0ee5c2d (patch) | |
tree | 9d7eabaa150a068689073981399173716f83f9a0 /src/cmd/go/internal/modload/query.go | |
parent | 0f7b4e72a054f974489d8342cdae5a6a7ba7a31b (diff) | |
download | go-8189a06190046cd69819ad1c6399943be0ee5c2d.tar.gz go-8189a06190046cd69819ad1c6399943be0ee5c2d.zip |
cmd/go/internal/modload: annotate replacements in PackageNotInModuleError
Fixes #34085
Change-Id: I3111f5997466ad33f51e80c71f5fb2ccebdcc6e4
Reviewed-on: https://go-review.googlesource.com/c/go/+/193617
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 | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/src/cmd/go/internal/modload/query.go b/src/cmd/go/internal/modload/query.go index f3c003a7cd..0359470d95 100644 --- a/src/cmd/go/internal/modload/query.go +++ b/src/cmd/go/internal/modload/query.go @@ -381,9 +381,10 @@ func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]Q r.Packages = match(r.Mod, root, isLocal) if len(r.Packages) == 0 { return r, &PackageNotInModuleError{ - Mod: r.Mod, - Query: query, - Pattern: pattern, + Mod: r.Mod, + Replacement: Replacement(r.Mod), + Query: query, + Pattern: pattern, } } return r, nil @@ -536,21 +537,32 @@ func (e *NoMatchingVersionError) Error() string { // code for the versions it knows about, and thus did not have the opportunity // to return a non-400 status code to suppress fallback. type PackageNotInModuleError struct { - Mod module.Version - Query string - Pattern string + Mod module.Version + Replacement module.Version + Query string + Pattern string } func (e *PackageNotInModuleError) Error() string { found := "" - if e.Query != e.Mod.Version { + if r := e.Replacement; r.Path != "" { + replacement := r.Path + if r.Version != "" { + replacement = fmt.Sprintf("%s@%s", r.Path, r.Version) + } + if e.Query == e.Mod.Version { + found = fmt.Sprintf(" (replaced by %s)", replacement) + } else { + found = fmt.Sprintf(" (%s, replaced by %s)", e.Mod.Version, replacement) + } + } else if e.Query != e.Mod.Version { found = fmt.Sprintf(" (%s)", e.Mod.Version) } if strings.Contains(e.Pattern, "...") { - return fmt.Sprintf("module %s@%s%s found, but does not contain packages matching %s", e.Mod.Path, e.Query, found, e.Pattern) + return fmt.Sprintf("module %s@%s found%s, but does not contain packages matching %s", e.Mod.Path, e.Query, found, e.Pattern) } - return fmt.Sprintf("module %s@%s%s found, but does not contain package %s", e.Mod.Path, e.Query, found, e.Pattern) + return fmt.Sprintf("module %s@%s found%s, but does not contain package %s", e.Mod.Path, e.Query, found, e.Pattern) } // ModuleHasRootPackage returns whether module m contains a package m.Path. |