Skip to content

Commit 2bafa82

Browse files
committed
fix: make 128 no packages found not return an error
1 parent 148a268 commit 2bafa82

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

internal/scanner/osv.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ import (
1313
)
1414

1515
type osvReferenceKind string
16+
type osvReturnCode int
1617

1718
const (
1819
OsvCommandName = "osv-scanner"
1920
AdvisoryKind osvReferenceKind = "ADVISORY"
2021
WebKind osvReferenceKind = "WEB"
2122
PackageKind osvReferenceKind = "PACKAGE"
2223
osvTimeout = 5 * time.Minute
24+
// https://google.github.io/osv-scanner/output/#return-codes
25+
osvReturnCodeSuccess osvReturnCode = 0
26+
osvReturnCodeVulnsFound osvReturnCode = 1
27+
osvReturnCodeNoPackages osvReturnCode = 128
2328
)
2429

2530
type osvSource struct {
@@ -116,10 +121,13 @@ func (s *osvScanner) Scan(dir string) (*OsvReport, error) {
116121
)
117122

118123
//Handle exit codes according to https://google.github.io/osv-scanner/output/#return-codes
119-
if cmdOut.ExitCode == 0 && err == nil {
124+
if cmdOut.ExitCode == int(osvReturnCodeSuccess) && err == nil {
120125
// Successful run of osv-scanner, no report because no vulnerabilities found
121126
log.Debug().Int("exitCode", cmdOut.ExitCode).Msg("osv-scanner did not find vulnerabilities")
122127
return nil, nil
128+
} else if cmdOut.ExitCode == int(osvReturnCodeNoPackages) {
129+
log.Warn().Int("exitCode", cmdOut.ExitCode).Msg("osv-scanner did not find any packages to scan")
130+
return nil, nil
123131
} else if cmdOut.ExitCode > 1 || cmdOut.ExitCode == -1 {
124132
// Failed to run osv-scanner at all, or it returned an error
125133
log.Debug().Int("exitCode", cmdOut.ExitCode).Msg("osv-scanner failed to run")

0 commit comments

Comments
 (0)