Skip to content

Commit b80fcba

Browse files
n-peugnetottok
authored andcommitted
estimate: fix for modules that don't have a go.mod file
1 parent 4c8eca8 commit b80fcba

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

estimate.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,12 @@ func getDirectDependencies(gopath, repodir, module string) (map[string]bool, err
110110
if err != nil {
111111
return nil, fmt.Errorf("get module dir: %w", err)
112112
}
113+
// We cannot use "go list -m ..." if there is no go.mod file, but
114+
// such packages are usually quite old and have few dependencies,
115+
// so we return a nil map without error.
116+
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err != nil {
117+
return nil, nil
118+
}
113119
cmd := exec.Command("go", "list", "-m", "-f", "{{if not .Indirect}}{{.Path}}{{end}}", "all")
114120
cmd.Dir = dir
115121
cmd.Stderr = os.Stderr

0 commit comments

Comments
 (0)