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

Commit a69c951

Browse files
committed
status: refactor return statements
Return explicit values instead of variables in runStatusAll().
1 parent 4e08f0a commit a69c951

File tree

1 file changed

+18
-30
lines changed

1 file changed

+18
-30
lines changed

cmd/dep/status.go

+18-30
Original file line numberDiff line numberDiff line change
@@ -235,22 +235,22 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
235235
}
236236
}
237237

238-
digestMismatch, hasMissingPkgs, errStatus := runStatusAll(ctx, out, p, sm)
239-
if errStatus.err != nil {
238+
digestMismatch, hasMissingPkgs, errCount, err := runStatusAll(ctx, out, p, sm)
239+
if err != nil {
240240
// If it's only update errors
241-
if errStatus.err == errFailedUpdate {
241+
if err == errFailedUpdate {
242242
// Print the results with unknown data
243243
ctx.Out.Println(buf.String())
244244

245245
// Print the help when in non-verbose mode
246246
if !ctx.Verbose {
247-
ctx.Out.Printf("The status of %d projects are unknown due to errors. Rerun with `-v` flag to see details.\n", errStatus.count)
247+
ctx.Out.Printf("The status of %d projects are unknown due to errors. Rerun with `-v` flag to see details.\n", errCount)
248248
}
249249
} else {
250250
// List package failure or multiple failures
251251
ctx.Out.Println("Failed to get status. Rerun with `-v` flag to see details.")
252252
}
253-
return errStatus.err
253+
return err
254254
}
255255

256256
if digestMismatch {
@@ -352,26 +352,16 @@ type MissingStatus struct {
352352
MissingPackages []string
353353
}
354354

355-
// errorStatus contains information about error and number of status failures.
356-
type errorStatus struct {
357-
err error
358-
// count is for counting errors due to which we don't fail completely, but
359-
// return partial results with missing/unknown data.
360-
count int
361-
}
362-
363-
func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceManager) (digestMismatch bool, hasMissingPkgs bool, errStatus errorStatus) {
355+
func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceManager) (digestMismatch bool, hasMissingPkgs bool, errCount int, err error) {
364356
if p.Lock == nil {
365-
errStatus.err = errors.Errorf("no Gopkg.lock found. Run `dep ensure` to generate lock file")
366-
return digestMismatch, hasMissingPkgs, errStatus
357+
return false, false, 0, errors.Errorf("no Gopkg.lock found. Run `dep ensure` to generate lock file")
367358
}
368359

369360
// While the network churns on ListVersions() requests, statically analyze
370361
// code from the current project.
371362
ptree, err := pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot))
372363
if err != nil {
373-
errStatus.err = errors.Wrapf(err, "analysis of local packages failed")
374-
return digestMismatch, hasMissingPkgs, errStatus
364+
return false, false, 0, errors.Wrapf(err, "analysis of local packages failed")
375365
}
376366

377367
// Set up a solver in order to check the InputHash.
@@ -391,13 +381,12 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
391381
}
392382

393383
if err := ctx.ValidateParams(sm, params); err != nil {
394-
return digestMismatch, hasMissingPkgs, errorStatus{err: err}
384+
return false, false, 0, err
395385
}
396386

397387
s, err := gps.Prepare(params, sm)
398388
if err != nil {
399-
errStatus.err = errors.Wrapf(err, "could not set up solver for input hashing")
400-
return digestMismatch, hasMissingPkgs, errStatus
389+
return false, false, 0, errors.Wrapf(err, "could not set up solver for input hashing")
401390
}
402391

403392
cm := collectConstraints(ptree, p, sm)
@@ -526,7 +515,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
526515

527516
// List Packages errors. This would happen only for dot output.
528517
if len(errListPkgCh) > 0 {
529-
errStatus.err = errFailedListPkg
518+
err = errFailedListPkg
530519
if ctx.Verbose {
531520
for err := range errListPkgCh {
532521
ctx.Err.Println(err.Error())
@@ -537,15 +526,15 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
537526

538527
// List Version errors
539528
if len(errListVerCh) > 0 {
540-
if errStatus.err == nil {
541-
errStatus.err = errFailedUpdate
529+
if err == nil {
530+
err = errFailedUpdate
542531
} else {
543-
errStatus.err = errMultipleFailures
532+
err = errMultipleFailures
544533
}
545534

546535
// Count ListVersions error because we get partial results when
547536
// this happens.
548-
errStatus.count = len(errListVerCh)
537+
errCount = len(errListVerCh)
549538
if ctx.Verbose {
550539
for err := range errListVerCh {
551540
ctx.Err.Println(err.Error())
@@ -569,7 +558,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
569558

570559
out.BasicFooter()
571560

572-
return digestMismatch, hasMissingPkgs, errStatus
561+
return false, false, errCount, err
573562
}
574563

575564
// Hash digest mismatch may indicate that some deps are no longer
@@ -578,7 +567,6 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
578567
//
579568
// It's possible for digests to not match, but still have a correct
580569
// lock.
581-
digestMismatch = true
582570
rm, _ := ptree.ToReachMap(true, true, false, nil)
583571

584572
external := rm.FlattenFn(paths.IsStandardImportPath)
@@ -611,7 +599,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
611599
ctx.Err.Printf("\t%s: %s\n", fail.ex, fail.err.Error())
612600
}
613601

614-
return digestMismatch, hasMissingPkgs, errorStatus{err: errors.New("address issues with undeducible import paths to get more status information")}
602+
return true, false, 0, errors.New("address issues with undeducible import paths to get more status information")
615603
}
616604

617605
out.MissingHeader()
@@ -631,7 +619,7 @@ outer:
631619
}
632620
out.MissingFooter()
633621

634-
return digestMismatch, hasMissingPkgs, errorStatus{}
622+
return true, hasMissingPkgs, 0, nil
635623
}
636624

637625
func formatVersion(v gps.Version) string {

0 commit comments

Comments
 (0)