@@ -445,7 +445,11 @@ func QueryPattern(pattern, query string, allowed func(module.Version) bool) ([]Q
445
445
candidateModules = modulePrefixesExcludingTarget (base )
446
446
)
447
447
if len (candidateModules ) == 0 {
448
- return nil , fmt .Errorf ("package %s is not in the main module (%s)" , pattern , Target .Path )
448
+ return nil , & PackageNotInModuleError {
449
+ Mod : Target ,
450
+ Query : query ,
451
+ Pattern : pattern ,
452
+ }
449
453
}
450
454
451
455
err := modfetch .TryProxies (func (proxy string ) error {
@@ -541,7 +545,9 @@ func queryPrefixModules(candidateModules []string, queryModule func(path string)
541
545
case nil :
542
546
found = append (found , r .QueryResult )
543
547
case * PackageNotInModuleError :
544
- if noPackage == nil {
548
+ // Given the option, prefer to attribute “package not in module”
549
+ // to modules other than the main one.
550
+ if noPackage == nil || noPackage .Mod == Target {
545
551
noPackage = rErr
546
552
}
547
553
case * NoMatchingVersionError :
@@ -626,6 +632,13 @@ type PackageNotInModuleError struct {
626
632
}
627
633
628
634
func (e * PackageNotInModuleError ) Error () string {
635
+ if e .Mod == Target {
636
+ if strings .Contains (e .Pattern , "..." ) {
637
+ return fmt .Sprintf ("main module (%s) does not contain packages matching %s" , Target .Path , e .Pattern )
638
+ }
639
+ return fmt .Sprintf ("main module (%s) does not contain package %s" , Target .Path , e .Pattern )
640
+ }
641
+
629
642
found := ""
630
643
if r := e .Replacement ; r .Path != "" {
631
644
replacement := r .Path
0 commit comments