diff --git a/src/babashka/impl/repl.clj b/src/babashka/impl/repl.clj index a2c2f302..c60b6cf9 100644 --- a/src/babashka/impl/repl.clj +++ b/src/babashka/impl/repl.clj @@ -11,11 +11,15 @@ [sci.impl.parser :as parser] [sci.impl.vars :as vars])) +(set! *warn-on-reflection* true) + (defn repl-caught "Default :caught hook for repl" - [e] + [^Throwable e] (sci/with-bindings {sci/out @sci/err} - (sio/println (.getMessage ^Exception e)) + (sio/println (str (.. e getClass getName) + (when-let [m (.getMessage e)] + (str ": " m)) )) (sio/flush))) (defn repl diff --git a/test/babashka/impl/repl_test.clj b/test/babashka/impl/repl_test.clj index 29a932c8..b914207b 100644 --- a/test/babashka/impl/repl_test.clj +++ b/test/babashka/impl/repl_test.clj @@ -3,8 +3,8 @@ [babashka.impl.repl :refer [start-repl!]] [clojure.string :as str] [clojure.test :as t :refer [deftest is]] - [sci.impl.opts :refer [init]] [sci.core :as sci] + [sci.impl.opts :refer [init]] [sci.impl.vars :as vars])) (set! *warn-on-reflection* true) @@ -24,6 +24,15 @@ (sci/with-in-str (str expr "\n:repl/quit") (repl!))) expected))) +(defn assert-repl-error [expr expected] + (is (str/includes? + (let [sw (java.io.StringWriter.)] + (sci/binding [sci/out (java.io.StringWriter.) + sci/err sw] + (sci/with-in-str (str expr "\n:repl/quit") + (repl!))) + (str sw)) expected))) + (deftest repl-test (assert-repl "1" "1") (assert-repl "[1 2 3]" "[1 2 3]") @@ -34,7 +43,8 @@ (assert-repl "1\n(inc *1)" "2") (assert-repl "1\n(dec *1)(+ *2 *2)" "2") (assert-repl "1\n(dec *1)(+ *2 *2)" "2") - (assert-repl "*command-line-args*" "[\"a\" \"b\" \"c\"]")) + (assert-repl "*command-line-args*" "[\"a\" \"b\" \"c\"]") + (assert-repl-error "(+ 1 nil)" "NullPointerException")) ;;;; Scratch