From 54ecf706d50733b31bcb452495ae991e913e2e24 Mon Sep 17 00:00:00 2001 From: Dan Holmsand Date: Wed, 14 Oct 2015 15:08:33 +0200 Subject: [PATCH] Rethrow errors caught during try-run --- src/reagent/ratom.cljs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/reagent/ratom.cljs b/src/reagent/ratom.cljs index 4c1e5bd..72658b3 100644 --- a/src/reagent/ratom.cljs +++ b/src/reagent/ratom.cljs @@ -335,7 +335,8 @@ (deftype Reaction [f ^:mutable state ^:mutable ^boolean dirty? ^boolean nocache? - ^:mutable watching ^:mutable watches ^:mutable auto-run] + ^:mutable watching ^:mutable watches ^:mutable auto-run + ^:mutable caught] IAtom IReactiveAtom @@ -394,9 +395,8 @@ (try (._run this) (catch :default e - ;; Just log error: it will most likely pop up again at deref time. - (error "Error in reaction:" e) (set! state nil) + (set! caught e) (notify-w this e nil))))) (_run [this] @@ -428,6 +428,9 @@ IDeref (-deref [this] + (when-some [e caught] + (set! caught nil) + (throw e)) (let [non-reactive (nil? *ratom-context*)] (when non-reactive (flush!)) @@ -467,7 +470,7 @@ (defn make-reaction [f & {:keys [auto-run on-set on-dispose]}] - (let [reaction (Reaction. f nil true false nil nil nil)] + (let [reaction (Reaction. f nil true false nil nil nil nil)] (._set-opts reaction {:auto-run auto-run :on-set on-set :on-dispose on-dispose})