@@ -13,13 +13,18 @@ import (
1313)
1414
1515type osvReferenceKind string
16+ type osvReturnCode int
1617
1718const (
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
2530type 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