Skip to content

Commit

Permalink
Merge pull request #560 from Masterminds/fix/287
Browse files Browse the repository at this point in the history
Fixed #287: When file or directory not found provide useful message
  • Loading branch information
mattfarina authored Aug 19, 2016
2 parents f934baa + 3140253 commit 8ec4e94
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
23 changes: 20 additions & 3 deletions dependency/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dependency

import (
"container/list"
"errors"
"runtime"
"sort"
//"go/build"
Expand Down Expand Up @@ -502,8 +503,9 @@ func (r *Resolver) resolveImports(queue *list.List, testDeps, addTest bool) ([]s
continue
}
} else if err != nil {
errStr := err.Error()
msg.Debug("ImportDir error on %s: %s", r.Handler.PkgPath(dep), err)
if strings.HasPrefix(err.Error(), "no buildable Go source") {
if strings.HasPrefix(errStr, "no buildable Go source") {
msg.Debug("No subpackages declared. Skipping %s.", dep)
continue
} else if os.IsNotExist(err) && !foundErr && !foundQ {
Expand All @@ -530,6 +532,16 @@ func (r *Resolver) resolveImports(queue *list.List, testDeps, addTest bool) ([]s
// see if this is on GOPATH and copy it?
msg.Info("Not found in vendor/: %s (1)", dep)
}
} else if strings.Contains(errStr, "no such file or directory") {
r.hadError[dep] = true
msg.Err("Error scanning %s: %s", dep, err)
msg.Err("This error means the referenced package was not found.")
msg.Err("Missing file or directory errors usually occur when multiple packages")
msg.Err("share a common dependency and the first reference encountered by the scanner")
msg.Err("sets the version to one that does not contain a subpackage needed required")
msg.Err("by another package that uses the shared dependency. Try setting a")
msg.Err("version in your glide.yaml that works for all packages that share this")
msg.Err("dependency.")
} else {
r.hadError[dep] = true
msg.Err("Error scanning %s: %s", dep, err)
Expand Down Expand Up @@ -576,10 +588,10 @@ func (r *Resolver) resolveImports(queue *list.List, testDeps, addTest bool) ([]s
r.VersionHandler.SetVersion(imp, addTest)
} else if err != nil {
r.hadError[dep] = true
msg.Warn("Error looking for %s: %s", imp, err)
msg.Err("Error looking for %s: %s", imp, err)
} else {
r.hadError[dep] = true
msg.Info("Not found: %s (2)", imp)
msg.Err("Not found: %s (2)", imp)
}
case LocGopath:
msg.Debug("Found on GOPATH, not vendor: %s", imp)
Expand All @@ -596,6 +608,11 @@ func (r *Resolver) resolveImports(queue *list.List, testDeps, addTest bool) ([]s

}

if len(r.hadError) > 0 {
// Errors occured so we return.
return []string{}, errors.New("Error resolving imports")
}

// FIXME: From here to the end is a straight copy of the resolveList() func.
res := make([]string, 0, queue.Len())

Expand Down
6 changes: 6 additions & 0 deletions dependency/resolver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func TestResolveLocalDeep(t *testing.T) {
if err != nil {
t.Fatal(err)
}
h := &DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}, Prefix: "../vendor"}
r.Handler = h

l, _, err := r.ResolveLocal(true)
if err != nil {
Expand All @@ -62,6 +64,8 @@ func TestResolve(t *testing.T) {
if err != nil {
t.Fatal(err)
}
h := &DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}, Prefix: "../vendor"}
r.Handler = h

base := filepath.Join(os.Getenv("GOPATH"), "src/github.com/Masterminds/glide/vendor")
l, err := r.Resolve("github.com/codegangsta/cli", base)
Expand Down Expand Up @@ -91,6 +95,8 @@ func TestResolveAll(t *testing.T) {
if err != nil {
t.Fatalf("No new resolver: %s", err)
}
h := &DefaultMissingPackageHandler{Missing: []string{}, Gopath: []string{}, Prefix: "../vendor"}
r.Handler = h
l, err := r.ResolveAll(deps, false)
if err != nil {
t.Fatalf("Failed to resolve: %s", err)
Expand Down

0 comments on commit 8ec4e94

Please sign in to comment.