Skip to content

Provide better exception when unable to resolve class while deserializing rulebase #264

@EthanEChristian

Description

@EthanEChristian

When a rulebase or session is serialized with a newer version of rules that may contain new records, if you try and deserialize the rulebase with older version of the rules file that doesn't contain these classes.

In the case described above while deserializing there is a null pointer thrown when trying to resolve the constructor symbol in the read-record function.

In this scenario i would expect the deserialization to fail, but provide a better exception when the constructor for the missing record.

Typically this sort of error would effect deserializing a session, however can effect the rulebase when a custom-fact-type function is provided and a record is used as the type in a condition for a rule. ex.

(defprotocol IFactType
  (fact-type [x]))

(defprotocol IAncestors
  (custom-ancestors [fact-type]))

(extend-type Object
  IFactType
  (fact-type [x] (type x))
  IAncestors
  (custom-ancestors [x]  (ancestors x)))

(defrecord CustomFact [fact-type value]
  IFactType
  (fact-type [x] fact-type))

(defrecord FactType [name]
  IAncestors
  (custom-ancestors [x]  #{CustomFact}))

(defrecord Outcome [final-value])

(def matching-fact (->FactType "Fact-1"))

(defrule some-rule
  [matching-fact [{:keys [value]}] (= ?value value)]
  =>
  (insert! (->Outcome ?value)))

(defquery get-outcomes
  []
  [Outcome (= ?final-value final-value)])

(def session (-> (mk-session [some-rule get-outcomes]
                             :fact-type-fn fact-type
                             :ancestors-fn custom-ancestors)
               (insert (->CustomFact (->FactType "Fact-1") 23))
               (fire-rules)))

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions