Improve internal errors.
This commit is contained in:
parent
8d13634c55
commit
dc26343727
|
@ -14,21 +14,21 @@
|
||||||
(defn- flatten-and-remove-nils
|
(defn- flatten-and-remove-nils
|
||||||
"`interceptors` might have nested collections, and contain nil elements.
|
"`interceptors` might have nested collections, and contain nil elements.
|
||||||
return a flat collection, with all nils removed.
|
return a flat collection, with all nils removed.
|
||||||
This function is 9/10 about giving good error messages"
|
This function is 9/10 about giving good error messages."
|
||||||
[id interceptors]
|
[id interceptors]
|
||||||
(let [make-chain #(->> % flatten (remove nil?))]
|
(let [make-chain #(->> % flatten (remove nil?))]
|
||||||
(if-not debug-enabled?
|
(if-not debug-enabled?
|
||||||
(make-chain interceptors)
|
(make-chain interceptors)
|
||||||
(do ;; do a whole lot of development time checks
|
(do ;; do a whole lot of development time checks
|
||||||
(when-not (coll? interceptors)
|
(when-not (coll? interceptors)
|
||||||
(console :error (str "re-frame: when registering " id ", expected a collection of interceptors, got:") interceptors))
|
(console :error "re-frame: when registering " id ", expected a collection of interceptors, got: " interceptors))
|
||||||
(let [chain (make-chain interceptors)]
|
(let [chain (make-chain interceptors)]
|
||||||
(when (empty? chain)
|
(when (empty? chain)
|
||||||
(console :error (str "re-frame: when registering" id ", given an empty interceptor chain")))
|
(console :error "re-frame: when registering " id ", given an empty interceptor chain"))
|
||||||
(when-let [not-i (first (remove interceptor/interceptor? chain))]
|
(when-let [not-i (first (remove interceptor/interceptor? chain))]
|
||||||
(if (fn? not-i)
|
(if (fn? not-i)
|
||||||
(console :error (str "re-frame: when registering " id ", got a function instead of an interceptor. Did you provide old style middleware by mistake? Got:") not-i)
|
(console :error "re-frame: when registering " id ", got a function instead of an interceptor. Did you provide old style middleware by mistake? Got: " not-i)
|
||||||
(console :error (str "re-frame: when registering " id ", expected interceptors, but got:") not-i)))
|
(console :error "re-frame: when registering " id ", expected interceptors, but got: " not-i)))
|
||||||
chain)))))
|
chain)))))
|
||||||
|
|
||||||
|
|
||||||
|
@ -39,7 +39,8 @@
|
||||||
at any level,so process this structure into a simple, nil-less vector
|
at any level,so process this structure into a simple, nil-less vector
|
||||||
before registration.
|
before registration.
|
||||||
|
|
||||||
An `event handler` will likely be at the end of the chain (wrapped in an interceptor)."
|
Typically, an `event handler` will be at the end of the chain (wrapped
|
||||||
|
in an interceptor)."
|
||||||
[id interceptors]
|
[id interceptors]
|
||||||
(register-handler kind id (flatten-and-remove-nils id interceptors)))
|
(register-handler kind id (flatten-and-remove-nils id interceptors)))
|
||||||
|
|
||||||
|
@ -50,12 +51,12 @@
|
||||||
(def ^:dynamic *handling* nil) ;; remember what event we are currently handling
|
(def ^:dynamic *handling* nil) ;; remember what event we are currently handling
|
||||||
|
|
||||||
(defn handle
|
(defn handle
|
||||||
"Given an event vector, look up the associated intercepter chain, and execute it."
|
"Given an event vector `event-v`, look up the associated interceptor chain, and execute it."
|
||||||
[event-v]
|
[event-v]
|
||||||
(let [event-id (first-in-vector event-v)]
|
(let [event-id (first-in-vector event-v)]
|
||||||
(if-let [interceptors (get-handler kind event-id true)]
|
(if-let [interceptors (get-handler kind event-id true)]
|
||||||
(if *handling*
|
(if *handling*
|
||||||
(console :error (str "re-frame: while handling \"" *handling* "\", dispatch-sync was called for \"" event-v "\". You can't call dispatch-sync within an event handler."))
|
(console :error "re-frame: while handling \"" *handling* "\", dispatch-sync was called for \"" event-v "\". You can't call dispatch-sync within an event handler.")
|
||||||
(binding [*handling* event-v]
|
(binding [*handling* event-v]
|
||||||
(trace/with-trace {:operation event-id
|
(trace/with-trace {:operation event-id
|
||||||
:op-type kind
|
:op-type kind
|
||||||
|
|
Loading…
Reference in New Issue