Skip to content

Commit fb242d0

Browse files
committed
fix: Handling go.mod parsing with no dependencies (regression from prior commit)
1 parent 56c5222 commit fb242d0

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

lens/module.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,8 +424,10 @@ func parseProjectDeps(projectDir string, preferNewest bool) (map[string]string,
424424
// versionsMap collects every version seen for each module path
425425
versionsMap := make(map[string][]string)
426426
var oldestGoVersion string
427+
var foundModule bool
427428

428429
if FileExists(rootMod) { // root module if present
430+
foundModule = true
429431
rootDeps, goVer, err := parseGoMod(rootMod)
430432
if err != nil {
431433
return nil, "", err
@@ -446,6 +448,7 @@ func parseProjectDeps(projectDir string, preferNewest bool) (map[string]string,
446448
if _, err := os.Stat(gm); err != nil {
447449
continue // skip missing or unreadable module rather than failing the whole parse
448450
}
451+
foundModule = true
449452
mdeps, goVer, err := parseGoMod(gm)
450453
if err != nil {
451454
return nil, "", err
@@ -474,7 +477,7 @@ func parseProjectDeps(projectDir string, preferNewest bool) (map[string]string,
474477
}
475478
deps[modPath] = chosen
476479
}
477-
if len(deps) == 0 {
480+
if !foundModule {
478481
return nil, "", fmt.Errorf("no go.mod or go.work found in %s", projectDir)
479482
}
480483
return deps, oldestGoVersion, nil

0 commit comments

Comments
 (0)