Skip to content

Commit 936723e

Browse files
committed
fix(envscan): handle rpm/dpkg error correctly
1 parent c15faa6 commit 936723e

2 files changed

Lines changed: 8 additions & 26 deletions

File tree

envinspection/inspection.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,18 +68,16 @@ func inspectInstalledSoftware(ctx context.Context, module *model.Module) {
6868
} else {
6969
LOG.Warnf("Software inspection error(%s): %s, ", fn, e)
7070
}
71-
if errors.Is(e, exec.ErrNotFound) {
72-
continue
73-
}
7471
foundCmd = true
75-
var cError cError
76-
if errors.As(e, &cError) {
77-
if cError.Content == "" {
78-
cError.Content = "(no stderr output)"
72+
var pError *exec.ExitError
73+
if errors.As(e, &pError) {
74+
var stderrText = strings.TrimSpace(string(pError.Stderr))
75+
if stderrText == "" {
76+
stderrText = "(no stderr output)"
7977
}
8078
scanerr.Add(ctx, scanerr.Param{
8179
Kind: "env_inspection_error",
82-
Content: cError.Content,
80+
Content: string(pError.Stderr),
8381
})
8482
}
8583
}

envinspection/utils.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,9 @@ import (
66
"os/exec"
77
)
88

9-
type cError struct {
10-
Content string
11-
Err error
12-
}
13-
14-
func (e cError) Error() string {
15-
return e.Err.Error()
16-
}
17-
189
func handleCmd(ctx context.Context, cmd *exec.Cmd) (string, error) {
19-
var stdout, stderr bytes.Buffer
10+
var stdout bytes.Buffer
2011
cmd.Stdout = &stdout
21-
cmd.Stderr = &stderr
2212
err := cmd.Run()
23-
if err != nil {
24-
return "", cError{
25-
Content: stderr.String(),
26-
Err: err,
27-
}
28-
}
29-
return stdout.String(), nil
13+
return stdout.String(), err
3014
}

0 commit comments

Comments
 (0)