From 95ea032d58f02326b61eb870c8ac746cf27fa1ae Mon Sep 17 00:00:00 2001 From: Peter Taoussanis Date: Wed, 3 Apr 2024 10:55:36 +0200 Subject: [PATCH] [new] [#389] Capture cause of failing error-fn --- src/taoensso/timbre.cljc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/taoensso/timbre.cljc b/src/taoensso/timbre.cljc index 48a119f..b4d4abe 100644 --- a/src/taoensso/timbre.cljc +++ b/src/taoensso/timbre.cljc @@ -794,6 +794,17 @@ ;;;; Default fns +(defn- pr-error + "Used as fallback error-fn" + [error] + (enc/try* + (pr-str error) + (catch :all _pr-str-error + (enc/try* + (str error) + (catch :all _str-error + ""))))) + (defn default-output-fn "Default (fn [data]) -> final output string, used to produce final formatted output_ string from final log data. @@ -843,13 +854,14 @@ (when-let [err ?err] (when-let [ef (get output-opts :error-fn default-output-error-fn)] (when-not (get output-opts :no-stacktrace?) ; Back compatibility - (enc/catching - (str enc/newline (ef data)) _ - (str - enc/newline - "[TIMBRE WARNING]: `error-fn` failed, falling back to `pr-str`:" - enc/newline - (enc/catching (pr-str err) _ "")))))))))) + (let [nl enc/newline] + (enc/try* + (str nl (ef data)) + (catch :all ef-error + (str nl + "[TIMBRE WARNING]: `error-fn` failed, falling back to `pr-error`." nl + "`error-fn` error: " nl (pr-error ef-error) nl nl + " Original error (given to `error-fn`): " nl (pr-error err)))))))))))) (defn- default-arg->str-fn [x] (enc/cond