Skip to content

Commit

Permalink
util: return type information in error
Browse files Browse the repository at this point in the history
Co-Authored-by: Annaraya Narasagond <[email protected]>
Signed-off-by: Raghavendra Talur <[email protected]>
  • Loading branch information
raghavendra-talur and asn1809 committed Dec 9, 2024
1 parent 73d5ee8 commit cec48f0
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/controller/util/json_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,27 +236,28 @@ func compareValues(val1, val2 interface{}, operator string) (bool, error) {
case float64:
v2, ok := val2.(float64)
if !ok {
return false, fmt.Errorf("mismatched types")
return false, fmt.Errorf("types mismatch: expected %T, actual: %T", val1, val2)
}

return compareFloat(v1, v2, operator)
case string:
v2, ok := val2.(string)
if !ok {
return false, fmt.Errorf("mismatched types")
return false, fmt.Errorf("types mismatch: expected %T, actual: %T", val1, val2)
}

return compareString(v1, v2, operator)
case bool:
v2, ok := val2.(bool)
if !ok {
return false, fmt.Errorf("mismatched types")
return false, fmt.Errorf("types mismatch: expected %T, actual: %T", val1, val2)
}

return compareBool(v1, v2, operator)
}

return false, fmt.Errorf("unsupported type or operator")
return false, fmt.Errorf("unsupported type or operator, types are %T and %T, operator is %s",
val1, val2, operator)
}

func isKindString(kind reflect.Kind) bool {
Expand Down

0 comments on commit cec48f0

Please sign in to comment.