Written by
Aaron Bell
on
on
Re-Frame interceptor errors prevent app state updates
One error in any interceptor prevents the second Re-Frame domino from falling. Either I wrote an error or clojure.spec changed since Jacek recorded his course, but my spec saw the db and threw an error. My spec function was in an interceptor, and this interceptor error prevented Re-Frame from updating the app-db, causing nothing to load in the app. Any error in any interceptor (including after interceptors) of an event handler will prevent app state updates and further effects. (I spent a painful number of days on this. I expected copying Jacek’s code to work, but I messed something up or the ecosystem’s changed.)
Interceptor:
(def check-spec-interceptor (rf/after (partial check-and-throw ::db)))
Interceptor function:
(defn check-and-throw
[a-spec db]
(when-not (s/valid? a-spec db)
(throw (ex-info (str "spec check faild: " (s/explain-str a-spec db)) {}))))
Error-throwing spec:
(s/def ::uid (s/nilable string?))
(s/def ::auth (s/map-of keyword? ::uid))
Ok spec:
(s/def ::auth (s/nilable (s/map-of keyword? (s/nilable string?))))