diff --git a/projects/main/src/taoensso/telemere.cljc b/projects/main/src/taoensso/telemere.cljc index a507dfd..d83b39d 100644 --- a/projects/main/src/taoensso/telemere.cljc +++ b/projects/main/src/taoensso/telemere.cljc @@ -332,17 +332,21 @@ See `uncaught->handler!` and `error!` for details." {:arglists (impl/signal-arglists :uncaught->error!)} [& args] - (let [msg-form ["Uncaught Throwable on thread: " `(.getName ~(with-meta '__thread {:tag 'java.lang.Thread}))] + (let [msg-form ["Uncaught Throwable on thread:" `(.getName ~(with-meta '__thread-arg {:tag 'java.lang.Thread}))] opts (impl/signal-opts `uncaught->error! (enc/get-source &form &env) {:kind :error, :level :error, :msg msg-form} - :error :id :dsc (into ['__throwable] args))] + :error :id :dsc (into ['__throwable-arg] args))] `(uncaught->handler! - (fn [~'__thread ~'__throwable] + (fn [~'__thread-arg ~'__throwable-arg] (impl/signal! ~opts)))))) -(comment (macroexpand '(uncaught->error! ::my-id))) +(comment + (macroexpand '(uncaught->error! ::uncaught)) + (do + (uncaught->error! ::uncaught) + (enc/threaded :user (/ 1 0)))) #?(:clj (defn uncaught->handler! @@ -352,9 +356,10 @@ See also `uncaught->error!`." [handler] (Thread/setDefaultUncaughtExceptionHandler - (reify Thread$UncaughtExceptionHandler - (uncaughtException [_ thread throwable] - (handler thread throwable)))) + (when handler ; falsey to remove + (reify Thread$UncaughtExceptionHandler + (uncaughtException [_ thread throwable] + (handler thread throwable))))) nil)) ;;;; Interop diff --git a/projects/main/test/taoensso/telemere_tests.cljc b/projects/main/test/taoensso/telemere_tests.cljc index a8a63df..1b4f479 100644 --- a/projects/main/test/taoensso/telemere_tests.cljc +++ b/projects/main/test/taoensso/telemere_tests.cljc @@ -671,6 +671,16 @@ (testing "Signals in go macros" [(async/go (tel/log! "hello"))])) +#?(:clj + (deftest _uncaught->handler! + (let [p (promise)] + [(do (tel/add-handler! ::p (fn ([]) ([sig] (p sig))) {}) :add-handler) + (is (nil? (tel/uncaught->error! ::uncaught))) + (do (enc/threaded :user (throw ex1)) :run-thread) + (is (sm? (deref p 2000 nil) {:kind :error, :level :error, :id ::uncaught, :error ex1})) + (is (nil? (tel/uncaught->error! nil))) + (do (tel/remove-handler! ::p) :remove-handler)]))) + ;;;; Interop (comment (def ^org.slf4j.Logger sl (org.slf4j.LoggerFactory/getLogger "my.class")))