mirror of
https://github.com/golang/go
synced 2024-11-17 12:54:47 -07:00
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>
This commit is contained in:
parent
956f64888d
commit
c739bc487d
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user