Skip to content

Commit d756493

Browse files
authored
Merge pull request #67 from elementsinteractive/osvcodes
fix: make 128 no packages found not return an error
2 parents 148a268 + 537c77d commit d756493

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

internal/scanner/osv.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ const (
2020
WebKind osvReferenceKind = "WEB"
2121
PackageKind osvReferenceKind = "PACKAGE"
2222
osvTimeout = 5 * time.Minute
23+
// https://google.github.io/osv-scanner/output/#return-codes
24+
osvReturnCodeSuccess int = 0
25+
osvReturnCodeVulnsFound int = 1
26+
osvReturnCodeNoPackages int = 128
2327
)
2428

2529
type osvSource struct {
@@ -116,10 +120,13 @@ func (s *osvScanner) Scan(dir string) (*OsvReport, error) {
116120
)
117121

118122
//Handle exit codes according to https://google.github.io/osv-scanner/output/#return-codes
119-
if cmdOut.ExitCode == 0 && err == nil {
123+
if cmdOut.ExitCode == osvReturnCodeSuccess && err == nil {
120124
// Successful run of osv-scanner, no report because no vulnerabilities found
121125
log.Debug().Int("exitCode", cmdOut.ExitCode).Msg("osv-scanner did not find vulnerabilities")
122126
return nil, nil
127+
} else if cmdOut.ExitCode == osvReturnCodeNoPackages {
128+
log.Warn().Int("exitCode", cmdOut.ExitCode).Msg("osv-scanner did not find any packages to scan")
129+
return nil, nil
123130
} else if cmdOut.ExitCode > 1 || cmdOut.ExitCode == -1 {
124131
// Failed to run osv-scanner at all, or it returned an error
125132
log.Debug().Int("exitCode", cmdOut.ExitCode).Msg("osv-scanner failed to run")

0 commit comments

Comments
 (0)