From 1e1151405af9ca519580a6d39192690cf4fd1bc3 Mon Sep 17 00:00:00 2001 From: Sunny Date: Sat, 23 Sep 2017 20:35:04 +0530 Subject: [PATCH] fix(status): skip ignored pkgs in missing pkgs chk This change skips the root packages from missing package check if there's a path to the corresponding package in manifest's ignored list. `digestMismatch` is removed from `runStatusAll()`. When there's a digest mismatch, it's an error. And we already log to stderr but never returned an actual error. `errInputDigestMismatch` is now returned as error when there's a digest mismatch. Some refactoring in how we handle the returned info from `runStatusAll()` and show the errors and their solutions. --- cmd/dep/status.go | 66 +++++++++++-------- .../ignore_lock_mismatch/final/Gopkg.lock | 9 +++ .../ignore_lock_mismatch/final/Gopkg.toml | 2 + .../ignore_lock_mismatch/initial/Gopkg.lock | 9 +++ .../ignore_lock_mismatch/initial/Gopkg.toml | 2 + .../ignore_lock_mismatch/initial/main.go | 8 +++ .../status/ignore_lock_mismatch/testcase.json | 7 ++ 7 files changed, 74 insertions(+), 29 deletions(-) create mode 100644 cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/final/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/final/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/Gopkg.lock create mode 100644 cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/Gopkg.toml create mode 100644 cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/main.go create mode 100644 cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/testcase.json diff --git a/cmd/dep/status.go b/cmd/dep/status.go index fa93507978..855a272660 100644 --- a/cmd/dep/status.go +++ b/cmd/dep/status.go @@ -49,9 +49,10 @@ const ( ) var ( - errFailedUpdate = errors.New("failed to fetch updates") - errFailedListPkg = errors.New("failed to list packages") - errMultipleFailures = errors.New("multiple sources of failure") + errFailedUpdate = errors.New("failed to fetch updates") + errFailedListPkg = errors.New("failed to list packages") + errMultipleFailures = errors.New("multiple sources of failure") + errInputDigestMismatch = errors.New("input-digest mismatch") ) func (cmd *statusCommand) Name() string { return "status" } @@ -235,36 +236,35 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error { } } - digestMismatch, hasMissingPkgs, errCount, err := runStatusAll(ctx, out, p, sm) + hasMissingPkgs, errCount, err := runStatusAll(ctx, out, p, sm) if err != nil { - // If it's only update errors - if err == errFailedUpdate { + switch err { + case errFailedUpdate: // Print the results with unknown data ctx.Out.Println(buf.String()) - // Print the help when in non-verbose mode if !ctx.Verbose { ctx.Out.Printf("The status of %d projects are unknown due to errors. Rerun with `-v` flag to see details.\n", errCount) } - } else { - // List package failure or multiple failures + case errInputDigestMismatch: + // Tell the user why mismatch happened and how to resolve it. + if hasMissingPkgs { + ctx.Err.Printf("Lock inputs-digest mismatch due to the following packages missing from the lock:\n\n") + ctx.Out.Print(buf.String()) + ctx.Err.Printf("\nThis happens when a new import is added. Run `dep ensure` to install the missing packages.\n") + } else { + ctx.Err.Printf("Lock inputs-digest mismatch. This happens when Gopkg.toml is modified.\n" + + "Run `dep ensure` to regenerate the inputs-digest.") + } + default: ctx.Out.Println("Failed to get status. Rerun with `-v` flag to see details.") } + return err } - if digestMismatch { - if hasMissingPkgs { - ctx.Err.Printf("Lock inputs-digest mismatch due to the following packages missing from the lock:\n\n") - ctx.Out.Print(buf.String()) - ctx.Err.Printf("\nThis happens when a new import is added. Run `dep ensure` to install the missing packages.\n") - } else { - ctx.Err.Printf("Lock inputs-digest mismatch. This happens when Gopkg.toml is modified.\n" + - "Run `dep ensure` to regenerate the inputs-digest.") - } - } else { - ctx.Out.Print(buf.String()) - } + // Print the status output + ctx.Out.Print(buf.String()) return nil } @@ -352,16 +352,16 @@ type MissingStatus struct { MissingPackages []string } -func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceManager) (digestMismatch bool, hasMissingPkgs bool, errCount int, err error) { +func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceManager) (hasMissingPkgs bool, errCount int, err error) { if p.Lock == nil { - return false, false, 0, errors.Errorf("no Gopkg.lock found. Run `dep ensure` to generate lock file") + return false, 0, errors.Errorf("no Gopkg.lock found. Run `dep ensure` to generate lock file") } // While the network churns on ListVersions() requests, statically analyze // code from the current project. ptree, err := pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot)) if err != nil { - return false, false, 0, errors.Wrapf(err, "analysis of local packages failed") + return false, 0, errors.Wrapf(err, "analysis of local packages failed") } // Set up a solver in order to check the InputHash. @@ -381,12 +381,12 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana } if err := ctx.ValidateParams(sm, params); err != nil { - return false, false, 0, err + return false, 0, err } s, err := gps.Prepare(params, sm) if err != nil { - return false, false, 0, errors.Wrapf(err, "could not set up solver for input hashing") + return false, 0, errors.Wrapf(err, "could not set up solver for input hashing") } cm := collectConstraints(ptree, p, sm) @@ -557,7 +557,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana out.BasicFooter() - return false, false, errCount, err + return false, errCount, err } // Hash digest mismatch may indicate that some deps are no longer @@ -598,11 +598,14 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana ctx.Err.Printf("\t%s: %s\n", fail.ex, fail.err.Error()) } - return true, false, 0, errors.New("address issues with undeducible import paths to get more status information") + return false, 0, errors.New("address issues with undeducible import paths to get more status information") } out.MissingHeader() + // Ignored packages. + igPkgs := p.Manifest.IgnoredPackages() + outer: for root, pkgs := range roots { // TODO also handle the case where the project is present, but there @@ -613,12 +616,17 @@ outer: } } + if _, ok := igPkgs[string(root)]; ok { + continue outer + } + hasMissingPkgs = true out.MissingLine(&MissingStatus{ProjectRoot: string(root), MissingPackages: pkgs}) } out.MissingFooter() - return true, hasMissingPkgs, 0, nil + // We are here because of an input-digest mismatch. Return error. + return hasMissingPkgs, 0, errInputDigestMismatch } func formatVersion(v gps.Version) string { diff --git a/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/final/Gopkg.lock b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/final/Gopkg.lock new file mode 100644 index 0000000000..bef2d0092e --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/final/Gopkg.lock @@ -0,0 +1,9 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/final/Gopkg.toml b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/final/Gopkg.toml new file mode 100644 index 0000000000..418ac251f8 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/final/Gopkg.toml @@ -0,0 +1,2 @@ +ignored = ["github.com/sdboyer/deptestdos"] + diff --git a/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/Gopkg.lock b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/Gopkg.lock new file mode 100644 index 0000000000..bef2d0092e --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/Gopkg.lock @@ -0,0 +1,9 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/Gopkg.toml b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/Gopkg.toml new file mode 100644 index 0000000000..418ac251f8 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/Gopkg.toml @@ -0,0 +1,2 @@ +ignored = ["github.com/sdboyer/deptestdos"] + diff --git a/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/main.go b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/main.go new file mode 100644 index 0000000000..935f86c58f --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/main.go @@ -0,0 +1,8 @@ +package main + +import ( + _ "github.com/sdboyer/deptestdos" +) + +func main() { +} diff --git a/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/testcase.json b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/testcase.json new file mode 100644 index 0000000000..cadfde4eb1 --- /dev/null +++ b/cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/testcase.json @@ -0,0 +1,7 @@ +{ + "commands": [ + ["status"] + ], + "error-expected": "inputs-digest mismatch", + "vendor-final": [] +}