Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 48be3da

Browse files
committedSep 11, 2017
status: refactor return statements
Return explicit values instead of variables in runStatusAll().
1 parent 2d25bff commit 48be3da

File tree

1 file changed

+18
-29
lines changed

1 file changed

+18
-29
lines changed
 

‎cmd/dep/status.go

+18-29
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,22 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
231231
}
232232
}
233233

234-
digestMismatch, hasMissingPkgs, errStatus := runStatusAll(ctx, out, p, sm)
235-
if errStatus.err != nil {
234+
digestMismatch, hasMissingPkgs, errCount, errStatus := runStatusAll(ctx, out, p, sm)
235+
if errStatus != nil {
236236
// If it's only update errors
237-
if errStatus.err == errFailedUpdate {
237+
if errStatus == errFailedUpdate {
238238
// Print the results with unknown data
239239
ctx.Out.Println(buf.String())
240240

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

252252
if digestMismatch {
@@ -348,26 +348,16 @@ type MissingStatus struct {
348348
MissingPackages []string
349349
}
350350

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

365356
// While the network churns on ListVersions() requests, statically analyze
366357
// code from the current project.
367358
ptree, err := pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot))
368359
if err != nil {
369-
errStatus.err = errors.Wrapf(err, "analysis of local packages failed")
370-
return digestMismatch, hasMissingPkgs, errStatus
360+
return false, false, 0, errors.Wrapf(err, "analysis of local packages failed")
371361
}
372362

373363
// Set up a solver in order to check the InputHash.
@@ -387,13 +377,12 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
387377
}
388378

389379
if err := ctx.ValidateParams(sm, params); err != nil {
390-
return digestMismatch, hasMissingPkgs, errorStatus{err: err}
380+
return false, false, 0, err
391381
}
392382

393383
s, err := gps.Prepare(params, sm)
394384
if err != nil {
395-
errStatus.err = errors.Wrapf(err, "could not set up solver for input hashing")
396-
return digestMismatch, hasMissingPkgs, errStatus
385+
return false, false, 0, errors.Wrapf(err, "could not set up solver for input hashing")
397386
}
398387

399388
cm := collectConstraints(ptree, p, sm)
@@ -522,7 +511,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
522511

523512
// List Packages errors. This would happen only for dot output.
524513
if len(errListPkgCh) > 0 {
525-
errStatus.err = errFailedListPkg
514+
errStatus = errFailedListPkg
526515
if ctx.Verbose {
527516
for err := range errListPkgCh {
528517
ctx.Err.Println(err.Error())
@@ -533,15 +522,15 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
533522

534523
// List Version errors
535524
if len(errListVerCh) > 0 {
536-
if errStatus.err == nil {
537-
errStatus.err = errFailedUpdate
525+
if errStatus == nil {
526+
errStatus = errFailedUpdate
538527
} else {
539-
errStatus.err = errMultipleFailures
528+
errStatus = errMultipleFailures
540529
}
541530

542531
// Count ListVersions error because we get partial results when
543532
// this happens.
544-
errStatus.count = len(errListVerCh)
533+
errCount = len(errListVerCh)
545534
if ctx.Verbose {
546535
for err := range errListVerCh {
547536
ctx.Err.Println(err.Error())
@@ -565,7 +554,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
565554

566555
out.BasicFooter()
567556

568-
return digestMismatch, hasMissingPkgs, errStatus
557+
return false, false, errCount, errStatus
569558
}
570559

571560
// Hash digest mismatch may indicate that some deps are no longer
@@ -607,7 +596,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
607596
ctx.Err.Printf("\t%s: %s\n", fail.ex, fail.err.Error())
608597
}
609598

610-
return digestMismatch, hasMissingPkgs, errorStatus{err: errors.New("address issues with undeducible import paths to get more status information")}
599+
return digestMismatch, hasMissingPkgs, 0, errors.New("address issues with undeducible import paths to get more status information")
611600
}
612601

613602
out.MissingHeader()
@@ -627,7 +616,7 @@ outer:
627616
}
628617
out.MissingFooter()
629618

630-
return digestMismatch, hasMissingPkgs, errorStatus{}
619+
return digestMismatch, hasMissingPkgs, 0, nil
631620
}
632621

633622
func formatVersion(v gps.Version) string {

0 commit comments

Comments
 (0)