Skip to content

Commit bf582ad

Browse files
authored
Improve error graph for failed solve (#1474)
1 parent 995ee5a commit bf582ad

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

pkg/apk/apk/repo.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -540,13 +540,13 @@ func (p *PkgResolver) GetPackageWithDependencies(pkgName string, existing map[st
540540

541541
pkg, err := p.resolvePackage(pkgName, dq)
542542
if err != nil {
543-
return nil, nil, nil, err
543+
return nil, nil, nil, &ConstraintError{pkgName, err}
544544
}
545545

546546
pin := cachedResolvePackageNameVersionPin(pkgName).pin
547547
deps, conflicts, err := p.getPackageDependencies(pkg, pin, true, parents, localExisting, existingOrigins, dq)
548548
if err != nil {
549-
return nil, nil, nil, err
549+
return nil, nil, nil, &DepError{pkg, err}
550550
}
551551
// eliminate duplication in dependencies
552552
added := make(map[string]*RepositoryPackage, len(deps))
@@ -605,14 +605,14 @@ func (p *PkgResolver) ResolvePackage(pkgName string, dq map[*RepositoryPackage]s
605605
name, version, compare, pin := constraint.name, constraint.version, constraint.dep, constraint.pin
606606
pkgsWithVersions, ok := p.nameMap[name]
607607
if !ok {
608-
return nil, fmt.Errorf("could not find package that provides %s in indexes", pkgName)
608+
return nil, fmt.Errorf("nothing provides %q", name)
609609
}
610610

611611
// pkgsWithVersions contains a map of all versions of the package
612612
// get the one that most matches what was requested
613613
packages := filterPackages(pkgsWithVersions, dq, withVersion(version, compare), withPreferPin(pin))
614614
if len(packages) == 0 {
615-
return nil, maybedqerror(pkgName, pkgsWithVersions, dq)
615+
return nil, maybedqerror(pkgsWithVersions, dq)
616616
}
617617
p.sortPackages(packages, nil, name, nil, nil, pin)
618618
pkgs := make([]*RepositoryPackage, 0, len(packages))
@@ -632,14 +632,14 @@ func (p *PkgResolver) resolvePackage(pkgName string, dq map[*RepositoryPackage]s
632632

633633
pkgsWithVersions, ok := p.nameMap[name]
634634
if !ok {
635-
return nil, fmt.Errorf("could not find package, alias or a package that provides %s in indexes", pkgName)
635+
return nil, fmt.Errorf("nothing provides %q", name)
636636
}
637637

638638
// pkgsWithVersions contains a map of all versions of the package
639639
// get the one that most matches what was requested
640640
packages := filterPackages(pkgsWithVersions, dq, withVersion(version, compare), withPreferPin(pin))
641641
if len(packages) == 0 {
642-
return nil, maybedqerror(pkgName, pkgsWithVersions, dq)
642+
return nil, maybedqerror(pkgsWithVersions, dq)
643643
}
644644
return p.bestPackage(packages, nil, name, nil, nil, pin).RepositoryPackage, nil
645645
}
@@ -688,7 +688,7 @@ func (p *PkgResolver) getPackageDependencies(pkg *RepositoryPackage, allowPin st
688688
constraints := slices.Clone(pkg.Dependencies)
689689

690690
if err := p.constrain(constraints, dq); err != nil {
691-
return nil, nil, fmt.Errorf("constraining deps for %q: %w", pkg.Filename(), err)
691+
return nil, nil, fmt.Errorf("constraining deps: %w", err)
692692
}
693693

694694
for len(constraints) != 0 {
@@ -736,7 +736,7 @@ func (p *PkgResolver) getPackageDependencies(pkg *RepositoryPackage, allowPin st
736736
// first see if it is a name of a package
737737
depPkgWithVersions, ok := p.nameMap[name]
738738
if !ok {
739-
return nil, nil, fmt.Errorf("could not find package either named %s or that provides %s for %s", dep, dep, pkg.Name)
739+
return nil, nil, &ConstraintError{dep, fmt.Errorf("nothing provides %q", name)}
740740
}
741741
// pkgsWithVersions contains a map of all versions of the package
742742
// get the one that most matches what was requested
@@ -747,7 +747,7 @@ func (p *PkgResolver) getPackageDependencies(pkg *RepositoryPackage, allowPin st
747747
withInstalledPackage(existing[name]),
748748
)
749749
if len(pkgs) == 0 {
750-
return nil, nil, &DepError{pkg, maybedqerror(dep, depPkgWithVersions, dq)}
750+
return nil, nil, &ConstraintError{dep, maybedqerror(depPkgWithVersions, dq)}
751751
}
752752
options[dep] = pkgs
753753
}
@@ -779,7 +779,7 @@ func (p *PkgResolver) getPackageDependencies(pkg *RepositoryPackage, allowPin st
779779

780780
best := p.bestPackage(pkgs, nil, name, existing, existingOrigins, "")
781781
if best == nil {
782-
return nil, nil, fmt.Errorf("could not find package for %q", name)
782+
return nil, nil, &ConstraintError{name, fmt.Errorf("could not find package for %q", name)}
783783
}
784784

785785
depPkg := best.RepositoryPackage
@@ -795,7 +795,7 @@ func (p *PkgResolver) getPackageDependencies(pkg *RepositoryPackage, allowPin st
795795
childParents[pkg.Name] = true
796796
subDeps, confs, err := p.getPackageDependencies(depPkg, allowPin, true, childParents, existing, existingOrigins, dq)
797797
if err != nil {
798-
return nil, nil, &DepError{pkg, err}
798+
return nil, nil, &ConstraintError{name, &DepError{depPkg, err}}
799799
}
800800
// first add the children, then the parent (depth-first)
801801
dependencies = append(dependencies, subDeps...)
@@ -1025,7 +1025,7 @@ func (e *DisqualifiedError) Unwrap() error {
10251025
return e.Wrapped
10261026
}
10271027

1028-
func maybedqerror(constraint string, pkgs []*repositoryPackage, dq map[*RepositoryPackage]string) error {
1028+
func maybedqerror(pkgs []*repositoryPackage, dq map[*RepositoryPackage]string) error {
10291029
errs := make([]error, 0, len(pkgs))
10301030
for _, pkg := range pkgs {
10311031
reason, ok := dq[pkg.RepositoryPackage]
@@ -1035,10 +1035,10 @@ func maybedqerror(constraint string, pkgs []*repositoryPackage, dq map[*Reposito
10351035
}
10361036

10371037
if len(errs) != 0 {
1038-
return &ConstraintError{constraint, errors.Join(errs...)}
1038+
return errors.Join(errs...)
10391039
}
10401040

1041-
return fmt.Errorf("could not find constraint %q in indexes", constraint)
1041+
return errors.New("not in indexes")
10421042
}
10431043

10441044
func disqualifyDifference(ctx context.Context, byArch map[string][]NamedIndex) map[*RepositoryPackage]string {

0 commit comments

Comments
 (0)