From 6aeb0869f8d7f83e0090006567e26354a78eb25f Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sat, 23 May 2020 21:23:57 +0200 Subject: [PATCH] Print exception name --- babashka.nrepl | 2 +- sci | 2 +- src/babashka/impl/repl.clj | 13 +++++++++---- src/babashka/main.clj | 9 +++++++-- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/babashka.nrepl b/babashka.nrepl index 0092be5f..38eef3c9 160000 --- a/babashka.nrepl +++ b/babashka.nrepl @@ -1 +1 @@ -Subproject commit 0092be5f97bc01f343b2e0619cbf1fe39149d498 +Subproject commit 38eef3c9eefe30944fc87127e715ed177ff425a8 diff --git a/sci b/sci index efcbbc70..f12f5caa 160000 --- a/sci +++ b/sci @@ -1 +1 @@ -Subproject commit efcbbc704bcf7fab513cda5fd8b9876bf30fedfe +Subproject commit f12f5caa82011412fd4d5cc3bb506d0a18b6d51d diff --git a/src/babashka/impl/repl.clj b/src/babashka/impl/repl.clj index 9e2674c8..467c9e79 100644 --- a/src/babashka/impl/repl.clj +++ b/src/babashka/impl/repl.clj @@ -17,10 +17,15 @@ "Default :caught hook for repl" [^Throwable e] (sci/with-bindings {sci/out @sci/err} - (sio/println (str (.. e getClass getName) - (when-let [m (.getMessage e)] - (str ": " m)) )) - (sio/flush))) + (let [d (ex-data e) + sci-error? (identical? :sci/error (:type d)) + ex-name (when sci-error? + (some-> ^Throwable (ex-cause e) + .getClass .getName))] + (sio/println (str ex-name + (when-let [m (.getMessage e)] + (str ": " m)) )) + (sio/flush)))) (defn repl "REPL with predefined hooks for attachable socket server." diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 6e86710c..85bf57b9 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -379,11 +379,16 @@ If neither -e, -f, or --socket-repl are specified, then the first argument that (defn error-handler* [^Exception e verbose?] (binding [*out* *err*] (let [d (ex-data e) - exit-code (:bb/exit-code d)] + exit-code (:bb/exit-code d) + sci-error? (identical? :sci/error (:type d)) + ex-name (when sci-error? + (some-> ^Throwable (ex-cause e) + .getClass .getName))] (if exit-code [nil exit-code] (do (if verbose? (print-stack-trace e) - (println (str (.. e getClass getName) + (println (str (or ex-name + (.. e getClass getName)) (when-let [m (.getMessage e)] (str ": " m)) ))) (flush)