oracle-samples/clara-rules

Fix error thrown when a common condition throws an exception in the LHS

Closed this issue · 2 comments

Given:

(defrule rule-1
  [Fact1]
  [Fact2 (< some-field 5)]
  =>
  (do-something))

(defrule rule-2
  [Fact3]
  [Fact2 (< some-field 5)]
  =>
  (do-something-else))

While inserting (->Fact2 nil) i would expect this to throw an error in the evaluation of the conditions in the LHS of both rules, and report the fact, conditions and rules that contain the conditions. This functionality was enhanced as part of #255.

However the actual result is another error being thrown:

java.lang.ClassCastException: clojure.lang.PersistentTreeSet cannot be cast to java.lang.Comparable

This is due to mishandling the scenario when a condition is common to multiple rules, see get-conditions-and-rule-names. Rather than conj, i think this should be into.

This looks like a pretty straightforward fix so I went ahead and merged the PR; we can leave the issue open for another day or two in case anyone else has thoughts on this after which I'll plan to close it.