[#308] print exception name in REPL
This commit is contained in:
parent
29ac221c20
commit
4263c19979
2 changed files with 18 additions and 4 deletions
|
|
@ -11,11 +11,15 @@
|
||||||
[sci.impl.parser :as parser]
|
[sci.impl.parser :as parser]
|
||||||
[sci.impl.vars :as vars]))
|
[sci.impl.vars :as vars]))
|
||||||
|
|
||||||
|
(set! *warn-on-reflection* true)
|
||||||
|
|
||||||
(defn repl-caught
|
(defn repl-caught
|
||||||
"Default :caught hook for repl"
|
"Default :caught hook for repl"
|
||||||
[e]
|
[^Throwable e]
|
||||||
(sci/with-bindings {sci/out @sci/err}
|
(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)))
|
(sio/flush)))
|
||||||
|
|
||||||
(defn repl
|
(defn repl
|
||||||
|
|
|
||||||
|
|
@ -3,8 +3,8 @@
|
||||||
[babashka.impl.repl :refer [start-repl!]]
|
[babashka.impl.repl :refer [start-repl!]]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clojure.test :as t :refer [deftest is]]
|
[clojure.test :as t :refer [deftest is]]
|
||||||
[sci.impl.opts :refer [init]]
|
|
||||||
[sci.core :as sci]
|
[sci.core :as sci]
|
||||||
|
[sci.impl.opts :refer [init]]
|
||||||
[sci.impl.vars :as vars]))
|
[sci.impl.vars :as vars]))
|
||||||
|
|
||||||
(set! *warn-on-reflection* true)
|
(set! *warn-on-reflection* true)
|
||||||
|
|
@ -24,6 +24,15 @@
|
||||||
(sci/with-in-str (str expr "\n:repl/quit")
|
(sci/with-in-str (str expr "\n:repl/quit")
|
||||||
(repl!))) expected)))
|
(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
|
(deftest repl-test
|
||||||
(assert-repl "1" "1")
|
(assert-repl "1" "1")
|
||||||
(assert-repl "[1 2 3]" "[1 2 3]")
|
(assert-repl "[1 2 3]" "[1 2 3]")
|
||||||
|
|
@ -34,7 +43,8 @@
|
||||||
(assert-repl "1\n(inc *1)" "2")
|
(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 "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
|
;;;; Scratch
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue