-
Notifications
You must be signed in to change notification settings - Fork 43
/
repl.clj
30 lines (29 loc) · 1.08 KB
/
repl.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(ns fipp.repl
(:require [clojure.repl :as clj]
[fipp.edn :refer [pprint]]))
(defn pst
"Like clojure.repl/pst, but with ex-info fipp pretty-printing."
([] (pst 12))
([e-or-depth]
(if (instance? Throwable e-or-depth)
(pst e-or-depth 12)
(when-let [e *e]
(pst (clj/root-cause e) e-or-depth))))
([^Throwable e depth]
(binding [*out* *err*]
(println (str (-> e class .getSimpleName) " " (.getMessage e)))
(when-let [info (ex-data e)]
(pprint info))
(let [st (.getStackTrace e)
cause (.getCause e)]
(doseq [el (take depth
(remove #(#{"clojure.lang.RestFn"
"clojure.lang.AFn"}
(.getClassName %))
st))]
(println (str \tab (clj/stack-element-str el))))
(when cause
(println "Caused by:")
(pst cause (min depth
(+ 2 (- (count (.getStackTrace cause))
(count st))))))))))