Skip to content

Commit 573a6f9

Browse files
committed
feat: add error handling for non eval result
1 parent 371978f commit 573a6f9

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

eval/cmdeval.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,17 @@ func (cv commandEvaluate) evalPolicy(commands []string, cmdExec cmd, evalExpr st
6666
policyEvalResults := make([]utils.PolicyResult, 0)
6767
var policyRes int
6868
if val, ok := resMap[compareComm]; ok {
69+
var policyResult utils.PolicyResult
6970
for _, cmdRes := range val {
7071
res, err := validator.NewPolicyEval().EvaluatePolicy(propertyEval, policy, cmdRes)
7172
if err != nil {
7273
return nil, err
7374
}
74-
policyResult := utils.MatchPolicy(res[0].ExpressionValue[0].Value, ReturnFields)
75+
if len(res) > 0 {
76+
policyResult = utils.MatchPolicy(res[0].ExpressionValue[0].Value, ReturnFields)
77+
} else {
78+
policyResult = utils.PolicyResult{ReturnValues: map[string]string{"allow": "false"}}
79+
}
7580
policyEvalResults = append(policyEvalResults, policyResult)
7681
}
7782
for _, per := range policyEvalResults {

0 commit comments

Comments
 (0)