From 19767b54a31c8f895de4de11697fc7baba9eb170 Mon Sep 17 00:00:00 2001 From: Michiel Borkent Date: Sun, 12 Jan 2020 17:40:41 +0100 Subject: [PATCH] [#221] print name of exception --- src/babashka/main.clj | 4 +++- test/babashka/main_test.clj | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/babashka/main.clj b/src/babashka/main.clj index 8606a932..f2f38d7f 100644 --- a/src/babashka/main.clj +++ b/src/babashka/main.clj @@ -247,7 +247,9 @@ Everything after that is bound to *command-line-args*.")) (if exit-code [nil exit-code] (do (if verbose? (print-stack-trace e) - (println (.getMessage e))) + (println (str (.. e getClass getName) + (when-let [m (.getMessage e)] + (str ": " m)) ))) (flush) [nil 1]))))) diff --git a/test/babashka/main_test.clj b/test/babashka/main_test.clj index f622fa72..90e65898 100644 --- a/test/babashka/main_test.clj +++ b/test/babashka/main_test.clj @@ -21,6 +21,10 @@ (is (thrown-with-msg? Exception #"does not exist" (bb nil "foo.clj"))) (is (thrown-with-msg? Exception #"does not exist" (bb nil "-help"))))) +(deftest print-error-test + (is (thrown-with-msg? Exception #"java.lang.NullPointerException" + (bb nil "(subs nil 0 0)")))) + (deftest main-test (testing "-io behaves as identity" (= "foo\nbar\n" (test-utils/bb "foo\nbar\n" "-io" "*input*")))