Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

gps: ProjectIdentifier: drop errString()method in favor of implicit String() calls #1096

Merged
merged 1 commit into from
Aug 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions internal/gps/identifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,13 @@ func (i ProjectIdentifier) normalizedSource() string {
return i.Source
}

func (i ProjectIdentifier) errString() string {
func (i ProjectIdentifier) String() string {
if i.Source == "" || i.Source == string(i.ProjectRoot) {
return string(i.ProjectRoot)
}
return fmt.Sprintf("%s (from %s)", i.ProjectRoot, i.Source)
}

func (i ProjectIdentifier) String() string {
return i.errString()
}

func (i ProjectIdentifier) normalize() ProjectIdentifier {
if i.Source == "" {
i.Source = string(i.ProjectRoot)
Expand Down
2 changes: 1 addition & 1 deletion internal/gps/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func (lp LockedProject) Packages() []string {

func (lp LockedProject) String() string {
return fmt.Sprintf("%s@%s with packages: %v",
lp.Ident().errString(), lp.Version(), lp.pkgs)
lp.Ident(), lp.Version(), lp.pkgs)
}

type safeLock struct {
Expand Down
8 changes: 4 additions & 4 deletions internal/gps/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -563,22 +563,22 @@ func TestMultiFetchThreadsafe(t *testing.T) {

switch op {
case 0:
t.Run(fmt.Sprintf("deduce:%v:%s", opcount, id.errString()), func(t *testing.T) {
t.Run(fmt.Sprintf("deduce:%v:%s", opcount, id), func(t *testing.T) {
t.Parallel()
if _, err := sm.DeduceProjectRoot(string(id.ProjectRoot)); err != nil {
t.Error(err)
}
})
case 1:
t.Run(fmt.Sprintf("sync:%v:%s", opcount, id.errString()), func(t *testing.T) {
t.Run(fmt.Sprintf("sync:%v:%s", opcount, id), func(t *testing.T) {
t.Parallel()
err := sm.SyncSourceFor(id)
if err != nil {
t.Error(err)
}
})
case 2:
t.Run(fmt.Sprintf("listVersions:%v:%s", opcount, id.errString()), func(t *testing.T) {
t.Run(fmt.Sprintf("listVersions:%v:%s", opcount, id), func(t *testing.T) {
t.Parallel()
vl, err := sm.ListVersions(id)
if err != nil {
Expand All @@ -589,7 +589,7 @@ func TestMultiFetchThreadsafe(t *testing.T) {
}
})
case 3:
t.Run(fmt.Sprintf("exists:%v:%s", opcount, id.errString()), func(t *testing.T) {
t.Run(fmt.Sprintf("exists:%v:%s", opcount, id), func(t *testing.T) {
t.Parallel()
y, err := sm.SourceExists(id)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions internal/gps/solve_basic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1350,15 +1350,15 @@ func (sm *depspecSourceManager) GetManifestAndLock(id ProjectIdentifier, v Versi
}

// TODO(sdboyer) proper solver-type errors
return nil, nil, fmt.Errorf("Project %s at version %s could not be found", id.errString(), v)
return nil, nil, fmt.Errorf("Project %s at version %s could not be found", id, v)
}

func (sm *depspecSourceManager) ExternalReach(id ProjectIdentifier, v Version) (map[string][]string, error) {
pid := pident{n: ProjectRoot(id.normalizedSource()), v: v}
if m, exists := sm.rm[pid]; exists {
return m, nil
}
return nil, fmt.Errorf("No reach data for %s at version %s", id.errString(), v)
return nil, fmt.Errorf("No reach data for %s at version %s", id, v)
}

func (sm *depspecSourceManager) ListPackages(id ProjectIdentifier, v Version) (pkgtree.PackageTree, error) {
Expand Down Expand Up @@ -1428,12 +1428,12 @@ func (sm *depspecSourceManager) ListVersions(id ProjectIdentifier) ([]PairedVers
// the test doesn't need revision info, anyway.
pvl = append(pvl, tv.Pair(Revision("FAKEREV")))
default:
panic(fmt.Sprintf("unreachable: type of version was %#v for spec %s", ds.v, id.errString()))
panic(fmt.Sprintf("unreachable: type of version was %#v for spec %s", ds.v, id))
}
}

if len(pvl) == 0 {
return nil, fmt.Errorf("Project %s could not be found", id.errString())
return nil, fmt.Errorf("Project %s could not be found", id)
}
return pvl, nil
}
Expand All @@ -1445,7 +1445,7 @@ func (sm *depspecSourceManager) RevisionPresentIn(id ProjectIdentifier, r Revisi
}
}

return false, fmt.Errorf("Project %s has no revision %s", id.errString(), r)
return false, fmt.Errorf("Project %s has no revision %s", id, r)
}

func (sm *depspecSourceManager) SourceExists(id ProjectIdentifier) (bool, error) {
Expand All @@ -1461,7 +1461,7 @@ func (sm *depspecSourceManager) SourceExists(id ProjectIdentifier) (bool, error)
func (sm *depspecSourceManager) SyncSourceFor(id ProjectIdentifier) error {
// Ignore err because it can't happen
if exist, _ := sm.SourceExists(id); !exist {
return fmt.Errorf("Source %s does not exist", id.errString())
return fmt.Errorf("Source %s does not exist", id)
}
return nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/gps/solve_bimodal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1208,7 +1208,7 @@ func (sm *bmSourceManager) ListPackages(id ProjectIdentifier, v Version) (pkgtre
}
}

return pkgtree.PackageTree{}, fmt.Errorf("Project %s at version %s could not be found", id.errString(), v)
return pkgtree.PackageTree{}, fmt.Errorf("Project %s at version %s could not be found", id, v)
}

func (sm *bmSourceManager) GetManifestAndLock(id ProjectIdentifier, v Version, an ProjectAnalyzer) (Manifest, Lock, error) {
Expand All @@ -1222,7 +1222,7 @@ func (sm *bmSourceManager) GetManifestAndLock(id ProjectIdentifier, v Version, a
}

// TODO(sdboyer) proper solver-type errors
return nil, nil, fmt.Errorf("Project %s at version %s could not be found", id.errString(), v)
return nil, nil, fmt.Errorf("Project %s at version %s could not be found", id, v)
}

// computeBimodalExternalMap takes a set of depspecs and computes an
Expand Down
30 changes: 15 additions & 15 deletions internal/gps/solve_failures.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func a2vs(a atom) string {
return "(root)"
}

return fmt.Sprintf("%s@%s", a.id.errString(), a.v)
return fmt.Sprintf("%s@%s", a.id, a.v)
}

type traceError interface {
Expand Down Expand Up @@ -95,7 +95,7 @@ type disjointConstraintFailure struct {
func (e *disjointConstraintFailure) Error() string {
if len(e.failsib) == 1 {
str := "Could not introduce %s, as it has a dependency on %s with constraint %s, which has no overlap with existing constraint %s from %s"
return fmt.Sprintf(str, a2vs(e.goal.depender), e.goal.dep.Ident.errString(), e.goal.dep.Constraint.String(), e.failsib[0].dep.Constraint.String(), a2vs(e.failsib[0].depender))
return fmt.Sprintf(str, a2vs(e.goal.depender), e.goal.dep.Ident, e.goal.dep.Constraint.String(), e.failsib[0].dep.Constraint.String(), a2vs(e.failsib[0].depender))
}

var buf bytes.Buffer
Expand All @@ -105,12 +105,12 @@ func (e *disjointConstraintFailure) Error() string {
sibs = e.failsib

str := "Could not introduce %s, as it has a dependency on %s with constraint %s, which has no overlap with the following existing constraints:\n"
fmt.Fprintf(&buf, str, a2vs(e.goal.depender), e.goal.dep.Ident.errString(), e.goal.dep.Constraint.String())
fmt.Fprintf(&buf, str, a2vs(e.goal.depender), e.goal.dep.Ident, e.goal.dep.Constraint.String())
} else {
sibs = e.nofailsib

str := "Could not introduce %s, as it has a dependency on %s with constraint %s, which does not overlap with the intersection of existing constraints from other currently selected packages:\n"
fmt.Fprintf(&buf, str, a2vs(e.goal.depender), e.goal.dep.Ident.errString(), e.goal.dep.Constraint.String())
fmt.Fprintf(&buf, str, a2vs(e.goal.depender), e.goal.dep.Ident, e.goal.dep.Constraint.String())
}

for _, c := range sibs {
Expand All @@ -122,7 +122,7 @@ func (e *disjointConstraintFailure) Error() string {

func (e *disjointConstraintFailure) traceString() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "constraint %s on %s disjoint with other dependers:\n", e.goal.dep.Constraint.String(), e.goal.dep.Ident.errString())
fmt.Fprintf(&buf, "constraint %s on %s disjoint with other dependers:\n", e.goal.dep.Constraint.String(), e.goal.dep.Ident)
for _, f := range e.failsib {
fmt.Fprintf(
&buf,
Expand Down Expand Up @@ -159,7 +159,7 @@ func (e *constraintNotAllowedFailure) Error() string {
return fmt.Sprintf(
"Could not introduce %s, as it has a dependency on %s with constraint %s, which does not allow the currently selected version of %s",
a2vs(e.goal.depender),
e.goal.dep.Ident.errString(),
e.goal.dep.Ident,
e.goal.dep.Constraint,
e.v,
)
Expand Down Expand Up @@ -198,7 +198,7 @@ func (e *versionNotAllowedFailure) Error() string {
"Could not introduce %s, as it is not allowed by constraint %s from project %s.",
a2vs(e.goal),
e.failparent[0].dep.Constraint.String(),
e.failparent[0].depender.id.errString(),
e.failparent[0].depender.id,
)
}

Expand Down Expand Up @@ -268,9 +268,9 @@ func (e *sourceMismatchFailure) traceString() string {
var buf bytes.Buffer
fmt.Fprintf(&buf, "disagreement on network addr for %s:\n", e.shared)

fmt.Fprintf(&buf, " %s from %s\n", e.mismatch, e.prob.id.errString())
fmt.Fprintf(&buf, " %s from %s\n", e.mismatch, e.prob.id)
for _, dep := range e.sel {
fmt.Fprintf(&buf, " %s from %s\n", e.current, dep.depender.id.errString())
fmt.Fprintf(&buf, " %s from %s\n", e.current, dep.depender.id)
}

return buf.String()
Expand Down Expand Up @@ -361,7 +361,7 @@ func (e *checkeeHasProblemPackagesFailure) traceString() string {
} else {
fmt.Fprintf(&buf, " required by:")
for _, pa := range errdep.deppers {
fmt.Fprintf(&buf, "\n\t\t%s at %s", pa.id.errString(), pa.v)
fmt.Fprintf(&buf, "\n\t\t%s at %s", pa.id, pa.v)
}
}
}
Expand Down Expand Up @@ -411,7 +411,7 @@ func (e *depHasProblemPackagesFailure) Error() string {
"Could not introduce %s, as it requires package %s from %s, but in version %s that package %s",
a2vs(e.goal.depender),
pkg,
e.goal.dep.Ident.errString(),
e.goal.dep.Ident,
e.v,
fcause(pkg),
)
Expand All @@ -421,7 +421,7 @@ func (e *depHasProblemPackagesFailure) Error() string {
fmt.Fprintf(
&buf, "Could not introduce %s, as it requires problematic packages from %s (current version %s):",
a2vs(e.goal.depender),
e.goal.dep.Ident.errString(),
e.goal.dep.Ident,
e.v,
)

Expand Down Expand Up @@ -451,7 +451,7 @@ func (e *depHasProblemPackagesFailure) traceString() string {
fmt.Fprintf(
&buf, "%s depping on %s at %s has problem subpkg(s):",
a2vs(e.goal.depender),
e.goal.dep.Ident.errString(),
e.goal.dep.Ident,
e.v,
)

Expand Down Expand Up @@ -481,7 +481,7 @@ func (e *nonexistentRevisionFailure) Error() string {
return fmt.Sprintf(
"Could not introduce %s, as it requires %s at revision %s, but that revision does not exist",
a2vs(e.goal.depender),
e.goal.dep.Ident.errString(),
e.goal.dep.Ident,
e.r,
)
}
Expand All @@ -491,6 +491,6 @@ func (e *nonexistentRevisionFailure) traceString() string {
"%s wants missing rev %s of %s",
a2vs(e.goal.depender),
e.r,
e.goal.dep.Ident.errString(),
e.goal.dep.Ident,
)
}
4 changes: 2 additions & 2 deletions internal/gps/solver.go
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ func (s *solver) getImportsAndConstraintsOf(a atomWithPackages) ([]string, []com
}

// Nope, it's actually full-on not there.
return nil, nil, fmt.Errorf("package %s does not exist within project %s", pkg, a.a.id.errString())
return nil, nil, fmt.Errorf("package %s does not exist within project %s", pkg, a.a.id)
}

for _, ex := range ie.External {
Expand Down Expand Up @@ -887,7 +887,7 @@ func (s *solver) findValidVersion(q *versionQueue, pl []string) error {

for {
cur := q.current()
s.traceInfo("try %s@%s", q.id.errString(), cur)
s.traceInfo("try %s@%s", q.id, cur)
err := s.check(atomWithPackages{
a: atom{
id: q.id,
Expand Down
12 changes: 6 additions & 6 deletions internal/gps/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (s *solver) traceCheckPkgs(bmi bimodalIdentifier) {
}

prefix := getprei(len(s.vqs) + 1)
s.tl.Printf("%s\n", tracePrefix(fmt.Sprintf("? revisit %s to add %v pkgs", bmi.id.errString(), len(bmi.pl)), prefix, prefix))
s.tl.Printf("%s\n", tracePrefix(fmt.Sprintf("? revisit %s to add %v pkgs", bmi.id, len(bmi.pl)), prefix, prefix))
}

func (s *solver) traceCheckQueue(q *versionQueue, bmi bimodalIdentifier, cont bool, offset int) {
Expand All @@ -53,7 +53,7 @@ func (s *solver) traceCheckQueue(q *versionQueue, bmi bimodalIdentifier, cont bo
verb = "attempt"
}

s.tl.Printf("%s\n", tracePrefix(fmt.Sprintf("%s? %s %s with %v pkgs; %s versions to try", indent, verb, bmi.id.errString(), len(bmi.pl), vlen), prefix, prefix))
s.tl.Printf("%s\n", tracePrefix(fmt.Sprintf("%s? %s %s with %v pkgs; %s versions to try", indent, verb, bmi.id, len(bmi.pl), vlen), prefix, prefix))
}

// traceStartBacktrack is called with the bmi that first failed, thus initiating
Expand All @@ -65,9 +65,9 @@ func (s *solver) traceStartBacktrack(bmi bimodalIdentifier, err error, pkgonly b

var msg string
if pkgonly {
msg = fmt.Sprintf("%s%s could not add %v pkgs to %s; begin backtrack", innerIndent, backChar, len(bmi.pl), bmi.id.errString())
msg = fmt.Sprintf("%s%s could not add %v pkgs to %s; begin backtrack", innerIndent, backChar, len(bmi.pl), bmi.id)
} else {
msg = fmt.Sprintf("%s%s no more versions of %s to try; begin backtrack", innerIndent, backChar, bmi.id.errString())
msg = fmt.Sprintf("%s%s no more versions of %s to try; begin backtrack", innerIndent, backChar, bmi.id)
}

prefix := getprei(len(s.sel.projects))
Expand All @@ -83,9 +83,9 @@ func (s *solver) traceBacktrack(bmi bimodalIdentifier, pkgonly bool) {

var msg string
if pkgonly {
msg = fmt.Sprintf("%s backtrack: popped %v pkgs from %s", backChar, len(bmi.pl), bmi.id.errString())
msg = fmt.Sprintf("%s backtrack: popped %v pkgs from %s", backChar, len(bmi.pl), bmi.id)
} else {
msg = fmt.Sprintf("%s backtrack: no more versions of %s to try", backChar, bmi.id.errString())
msg = fmt.Sprintf("%s backtrack: no more versions of %s to try", backChar, bmi.id)
}

prefix := getprei(len(s.sel.projects))
Expand Down