Skip to content

Commit

Permalink
fix: improve handling if docker exits with a non-zero code when try…
Browse files Browse the repository at this point in the history
…ing to scan images
  • Loading branch information
G-Rath committed Sep 29, 2024
1 parent 259b6d4 commit 350b160
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions pkg/osvscanner/osvscanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,35 @@ func scanDebianDocker(r reporter.Reporter, dockerImageName string) ([]scannedPac
r.Errorf("Failed to get stdout: %s\n", err)
return nil, err
}
stderr, err := cmd.StderrPipe()

if err != nil {
r.Errorf("Failed to get stderr: %s\n", err)
return nil, err
}

err = cmd.Start()
if err != nil {
r.Errorf("Failed to start docker image: %s\n", err)
return nil, err
}
// TODO: Do error checking here
//nolint:errcheck
defer cmd.Wait()
defer func() {
var stderrlines []string

scanner := bufio.NewScanner(stderr)
for scanner.Scan() {
stderrlines = append(stderrlines, scanner.Text())
}

err := cmd.Wait()
if err != nil {
r.Errorf("Docker command exited with code %d\n", cmd.ProcessState.ExitCode())
for _, line := range stderrlines {
r.Errorf("> %s\n", line)
}
}
}()

scanner := bufio.NewScanner(stdout)
var packages []scannedPackage
for scanner.Scan() {
Expand Down

0 comments on commit 350b160

Please sign in to comment.