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

Commit

Permalink
status: log errors and failure feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
darkowlzz committed Sep 9, 2017
1 parent 60e5c84 commit e70cafa
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 9 deletions.
54 changes: 45 additions & 9 deletions cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ print an extended status output for each dependency of the project.
Status returns exit code zero if all dependencies are in a "good state".
`

var errFailedUpdate = errors.New("failed to fetch updates")

func (cmd *statusCommand) Name() string { return "status" }
func (cmd *statusCommand) Args() string { return "[package...]" }
func (cmd *statusCommand) ShortHelp() string { return statusShortHelp }
Expand Down Expand Up @@ -98,7 +100,7 @@ func (out *tableOutput) BasicLine(bs *BasicStatus) {
bs.getConsolidatedConstraint(),
formatVersion(bs.Version),
formatVersion(bs.Revision),
formatVersion(bs.Latest),
bs.getConsolidatedLatest(),
bs.PackageCount,
)
}
Expand Down Expand Up @@ -222,6 +224,15 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {

digestMismatch, hasMissingPkgs, err := runStatusAll(ctx, out, p, sm)
if err != nil {
// Print the outdated results
if err == errFailedUpdate {
ctx.Out.Println(buf.String())

// Print the help when in non-verbose mode
if !ctx.Verbose {
ctx.Out.Println("Failed to get status of some projects. Run `dep status -v` to see the error messages.")
}
}
return err
}

Expand All @@ -245,8 +256,8 @@ type rawStatus struct {
ProjectRoot string
Constraint string
Version string
Revision gps.Revision
Latest gps.Version
Revision string
Latest string
PackageCount int
}

Expand All @@ -261,6 +272,7 @@ type BasicStatus struct {
Latest gps.Version
PackageCount int
hasOverride bool
hasError bool
}

func (bs *BasicStatus) getConsolidatedConstraint() string {
Expand Down Expand Up @@ -288,13 +300,26 @@ func (bs *BasicStatus) getConsolidatedVersion() string {
return version
}

func (bs *BasicStatus) getConsolidatedLatest() string {
latest := ""
if bs.Latest != nil {
latest = formatVersion(bs.Latest)
}

if bs.hasError {
latest += "unknown"
}

return latest
}

func (bs *BasicStatus) marshalJSON() *rawStatus {
return &rawStatus{
ProjectRoot: bs.ProjectRoot,
Constraint: bs.getConsolidatedConstraint(),
Version: formatVersion(bs.Version),
Revision: bs.Revision,
Latest: bs.Latest,
Revision: formatVersion(bs.Revision),
Latest: bs.getConsolidatedLatest(),
PackageCount: bs.PackageCount,
}
}
Expand Down Expand Up @@ -390,6 +415,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
ptr, err := sm.ListPackages(proj.Ident(), proj.Version())

if err != nil {
bs.hasError = true
errorCh <- err
}

Expand Down Expand Up @@ -445,6 +471,11 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
break
}
}
} else {
// Failed to fetch version list (could happen due to
// network issue)
bs.hasError = true
errorCh <- err
}
}

Expand All @@ -458,11 +489,16 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
close(errorCh)
logger.Println()

var updateError error

if len(errorCh) > 0 {
for err := range errorCh {
ctx.Err.Println(err.Error())
updateError = errFailedUpdate
if ctx.Verbose {
for err := range errorCh {
ctx.Err.Println(err.Error())
}
ctx.Err.Println()
}
ctx.Err.Println()
}

// A map of ProjectRoot and *BasicStatus. This is used in maintain the
Expand All @@ -480,7 +516,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana

out.BasicFooter()

return digestMismatch, hasMissingPkgs, nil
return digestMismatch, hasMissingPkgs, updateError
}

// Hash digest mismatch may indicate that some deps are no longer
Expand Down
10 changes: 10 additions & 0 deletions cmd/dep/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ func TestBasicLine(t *testing.T) {
wantJSONStatus: []string{`"Revision":"revxyz"`, `"Constraint":"1.2.3"`, `"Version":"1.0.0"`},
wantTableStatus: []string{`github.com/foo/bar 1.2.3 1.0.0 revxyz 0`},
},
{
name: "BasicStatus with update error",
status: BasicStatus{
ProjectRoot: "github.com/foo/bar",
hasError: true,
},
wantDotStatus: []string{`[label="github.com/foo/bar"];`},
wantJSONStatus: []string{`"Version":""`, `"Revision":""`, `"Latest":"unknown"`},
wantTableStatus: []string{`github.com/foo/bar unknown 0`},
},
}

for _, test := range tests {
Expand Down

0 comments on commit e70cafa

Please sign in to comment.