Skip to content

Commit 9b7ef87

Browse files
authored
Update lint_rego.go
Add type assertion and check for empty `"errors"` array returned from rule to prevent crashes when converting to `[]interface{}`
1 parent d9db9b0 commit 9b7ef87

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

lint/lint_rego.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ func evalTestcase_Rego(rulePath string, queryString string, inputFilePath string
7272
log.Debugf("Result: %v", rs)
7373
rsmap := rs[0].Expressions[0].Value.(map[string]interface{})
7474
result := rsmap["allow"].(bool)
75-
errors := rsmap["errors"].([]interface{})
75+
errors, ok := rsmap["errors"].([]interface{})
76+
77+
if !ok || errors == nil {
78+
errors = []interface{}{}
79+
}
80+
7681
if !result {
7782
myErrors := make([]string, 0)
7883
for _, err := range errors {

0 commit comments

Comments
 (0)