Add log-ex middleware.
This commit is contained in:
parent
13058912ed
commit
a5b1ccdb16
|
@ -65,13 +65,5 @@
|
|||
handler-fn (lookup-handler event-id)]
|
||||
(if (nil? handler-fn)
|
||||
(warn "re-frame: no event handler registered for: \"" event-id "\". Ignoring.") ;; TODO: make exception
|
||||
(try
|
||||
(handler-fn app-db event-v)
|
||||
(catch :default e
|
||||
(do
|
||||
;; use of a core.async loop seems to completely ruin exception stacks.
|
||||
;; So we're going print the exception to the console here, before it gets trashed.
|
||||
(.error js/console e.stack)
|
||||
(throw e)))))))
|
||||
|
||||
(handler-fn app-db event-v))))
|
||||
|
||||
|
|
|
@ -35,6 +35,25 @@
|
|||
(if-not (identical? db new-db)
|
||||
(reset! app-db new-db)))))))
|
||||
|
||||
(defn log-ex
|
||||
"Middleware which catches and prints any handler-generated exceptions to console.
|
||||
Handlers are called from within a core.async go-loop, and core.async produces
|
||||
a special kind of hell when in comes to stacktraces. By the time an exception
|
||||
has passed through a go-loop its stack is mangled beyond repair and you'll
|
||||
have no idea where the exception was thrown.
|
||||
So this middleware catches and prints to stacktrace before the core.async sausage
|
||||
machine has done its work.
|
||||
"
|
||||
[handler]
|
||||
(fn log-ex-handler
|
||||
[db v]
|
||||
(try
|
||||
(handler db v)
|
||||
(catch :default e ;; ooops, handler threw
|
||||
(do
|
||||
(.error js/console e.stack)
|
||||
(throw e))))))
|
||||
|
||||
|
||||
(defn debug
|
||||
"Middleware which logs debug information to js/console for each event.
|
||||
|
|
Loading…
Reference in New Issue