Skip to content

Commit 691e3e0

Browse files
tooryxcopybara-github
authored andcommitted
Do not return errors if no lockfile has been found, as it would cause all of Scalibr to be in error.
PiperOrigin-RevId: 813320729
1 parent d45db2e commit 691e3e0

2 files changed

Lines changed: 18 additions & 9 deletions

File tree

annotator/misc/fromnpm/fromnpm.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ func ResolvedFromLockfile(root string, fsys scalibrfs.FS) (map[string]bool, erro
130130
errs = append(errs, fmt.Errorf("failed to resolve lockfile: %w", err))
131131
continue
132132
}
133+
134+
if parsedLockfile == nil {
135+
continue
136+
}
137+
133138
return registryResolvedPackages(parsedLockfile), nil
134139
}
135140
return nil, errors.Join(errs...)
@@ -207,6 +212,10 @@ func packageName(name string) string {
207212
func npmLockfile(lockfile string, fsys scalibrfs.FS) (*packagelockjson.LockFile, error) {
208213
data, err := fs.ReadFile(fsys, lockfile)
209214
if err != nil {
215+
if errors.Is(err, fs.ErrNotExist) {
216+
return nil, nil
217+
}
218+
210219
return nil, err
211220
}
212221

annotator/misc/fromnpm/fromnpm_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func TestAnnotate_LockfileV1(t *testing.T) {
239239
FromNPMRepository: false,
240240
},
241241
},
242-
wantAnyErr: true,
242+
wantAnyErr: false,
243243
},
244244
}
245245

@@ -448,7 +448,7 @@ func TestAnnotate_LockfileV2(t *testing.T) {
448448
FromNPMRepository: false,
449449
},
450450
},
451-
wantAnyErr: true,
451+
wantAnyErr: false,
452452
},
453453
}
454454

@@ -645,28 +645,28 @@ func TestResolvedFromLockfile(t *testing.T) {
645645
skipWindows: true,
646646
},
647647
{
648-
name: "parse with no lockfiles returns error",
648+
name: "parse with no lockfiles returns nothing",
649649
lockfiles: map[string]string{},
650650
wantDeps: nil,
651-
wantAnyErr: true,
651+
wantAnyErr: false,
652652
skipWindows: false,
653653
},
654654
{
655655
name: "parse empty lockfiles returns error",
656656
lockfiles: map[string]string{
657-
"testproject/node_modules/package-lock.json": "empty-file.json",
657+
"testproject/node_modules/.package-lock.json": "empty-file.json",
658658
},
659659
wantDeps: nil,
660660
wantAnyErr: true,
661661
skipWindows: true,
662662
},
663663
{
664-
name: "parse lockfiles without dependencies and packages returns error",
664+
name: "parse lockfiles without dependencies and packages returns nothing",
665665
lockfiles: map[string]string{
666-
"testproject/node_modules/package-lock.json": "testdata/no-dep-list-package-lock.json",
666+
"testproject/node_modules/.package-lock.json": "testdata/no-dep-list-package-lock.json",
667667
},
668-
wantDeps: nil,
669-
wantAnyErr: true,
668+
wantDeps: map[string]bool{},
669+
wantAnyErr: false,
670670
skipWindows: true,
671671
},
672672
}

0 commit comments

Comments
 (0)