Skip to content

Commit b42aeb7

Browse files
committed
fix(envscan): error handling
1 parent de7de18 commit b42aeb7

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

envinspection/inspection.go

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/murphysecurity/murphysec/infra/logctx"
99
"github.com/murphysecurity/murphysec/model"
1010
"github.com/murphysecurity/murphysec/scanerr"
11+
"os"
1112
"os/exec"
1213
"reflect"
1314
"runtime"
@@ -59,27 +60,30 @@ func inspectInstalledSoftware(ctx context.Context, module *model.Module) {
5960
}
6061
var foundCmd = false
6162
for _, f := range scanFunc {
62-
pkgs, e := f(ctx)
6363
var fn = strings.TrimPrefix(runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name(), "github.com/murphysecurity/murphysec/envinspection.")
64-
if e == nil && len(pkgs) > 0 {
65-
module.Dependencies = append(module.Dependencies, pkgs...)
66-
LOG.Infof("inspection succeeded(%s), total %d items", fn, len(pkgs))
67-
continue
68-
} else {
64+
pkgs, e := f(ctx)
65+
if e != nil {
6966
LOG.Warnf("Software inspection error(%s): %s, ", fn, e)
70-
}
71-
foundCmd = true
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)"
67+
var pError *exec.ExitError
68+
if errors.As(e, &pError) {
69+
var stderrText = strings.TrimSpace(string(pError.Stderr))
70+
if stderrText == "" {
71+
stderrText = "(no stderr output)"
72+
}
73+
scanerr.Add(ctx, scanerr.Param{
74+
Kind: "env_inspection_error",
75+
Content: string(pError.Stderr),
76+
})
77+
continue
78+
}
79+
if os.IsNotExist(e) {
80+
continue
7781
}
78-
scanerr.Add(ctx, scanerr.Param{
79-
Kind: "env_inspection_error",
80-
Content: string(pError.Stderr),
81-
})
82+
foundCmd = true
83+
continue
8284
}
85+
module.Dependencies = append(module.Dependencies, pkgs...)
86+
foundCmd = true
8387
}
8488
if !foundCmd {
8589
scanerr.Add(ctx, scanerr.Param{

0 commit comments

Comments
 (0)