Skip to content

Commit

Permalink
🐛 Handle osvscanner errors on projects with no dependencies (#3803)
Browse files Browse the repository at this point in the history
* handle osv errors for projects without packages

Signed-off-by: Spencer Schrock <sschrock@google.com>

* make test parallel

Signed-off-by: Spencer Schrock <sschrock@google.com>

---------

Signed-off-by: Spencer Schrock <sschrock@google.com>
  • Loading branch information
spencerschrock committed Jan 19, 2024
1 parent 51f1732 commit b556d93
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clients/osv.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func (v osvClient) ListUnfixedVulnerabilities(

response := VulnerabilitiesResponse{}

if err == nil { // No vulns found
// either no vulns found, or no packages detected by osvscanner, which likely means no vulns
// while there could still be vulns, not detecting any packages shouldn't be a runtime error.
if err == nil || errors.Is(err, osvscanner.NoPackagesFoundErr) {
return response, nil
}

Expand Down
12 changes: 12 additions & 0 deletions clients/osv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package clients

import (
"context"
"reflect"
"testing"
)
Expand Down Expand Up @@ -46,3 +47,14 @@ func TestRemoveDuplicate(t *testing.T) {
})
}
}

func TestEmptyProject(t *testing.T) {
t.Parallel()
var client osvClient
var commit string
emptyDir := t.TempDir()
_, err := client.ListUnfixedVulnerabilities(context.Background(), commit, emptyDir)
if err != nil {
t.Fatalf("empty directory shouldn't throw an error: %v", err)
}
}

0 comments on commit b556d93

Please sign in to comment.