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

Commit bd9c433

Browse files
committed
status: return error from collectConstraints()
1 parent 17156e8 commit bd9c433

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

cmd/dep/status.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,10 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
417417
return false, 0, errors.Wrapf(err, "could not set up solver for input hashing")
418418
}
419419

420-
cm := collectConstraints(ctx, p, sm)
420+
cm, err := collectConstraints(ctx, p, sm)
421+
if err != nil {
422+
return false, 0, err
423+
}
421424

422425
// Get the project list and sort it so that the printed output users see is
423426
// deterministically ordered. (This may be superfluous if the lock is always
@@ -684,7 +687,7 @@ type projectConstraint struct {
684687
type constraintsCollection map[string][]projectConstraint
685688

686689
// collectConstraints collects constraints declared by all the dependencies.
687-
func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) constraintsCollection {
690+
func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) (constraintsCollection, error) {
688691
logger := ctx.Err
689692
if !ctx.Verbose {
690693
logger = log.New(ioutil.Discard, "", 0)
@@ -695,7 +698,7 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) cons
695698
// Get direct deps of the root project.
696699
_, directDeps, err := getDirectDependencies(sm, p)
697700
if err != nil {
698-
logger.Println("Error getting direct deps:", err)
701+
return nil, err
699702
}
700703

701704
// Create a root analyzer.
@@ -751,12 +754,13 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) cons
751754
close(errCh)
752755

753756
if len(errCh) > 0 {
754-
for err := range errCh {
755-
logger.Println(err.Error())
757+
err = errors.New("failed to collect constraints")
758+
for e := range errCh {
759+
logger.Println(e.Error())
756760
}
757761
}
758762

759-
return constraintCollection
763+
return constraintCollection, err
760764
}
761765

762766
type byProject []projectConstraint

cmd/dep/status_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func TestCollectConstraints(t *testing.T) {
398398

399399
for _, c := range cases {
400400
t.Run(c.name, func(t *testing.T) {
401-
gotConstraints := collectConstraints(ctx, &c.project, sm)
401+
gotConstraints, _ := collectConstraints(ctx, &c.project, sm)
402402

403403
if !reflect.DeepEqual(gotConstraints, c.wantConstraints) {
404404
t.Fatalf("Unexpected collected constraints: \n\t(GOT): %v\n\t(WNT): %v", gotConstraints, c.wantConstraints)

0 commit comments

Comments
 (0)