parent
697c03fa07
commit
86c67af49c
3 changed files with 33 additions and 6 deletions
2
process
2
process
|
|
@ -1 +1 @@
|
||||||
Subproject commit 7847bdd56bb8db3293070a5c09b94dddc77c0155
|
Subproject commit cc298e4a75e307f1265dcce11c629ea088423a9e
|
||||||
|
|
@ -18,18 +18,18 @@
|
||||||
(drop (- stack-count 5) stacktrace)]))))
|
(drop (- stack-count 5) stacktrace)]))))
|
||||||
|
|
||||||
(defn print-stacktrace
|
(defn print-stacktrace
|
||||||
[stacktrace {:keys [:verbose?]}]
|
[stacktrace {:keys [:debug]}]
|
||||||
(let [stacktrace (sci/format-stacktrace stacktrace)
|
(let [stacktrace (sci/format-stacktrace stacktrace)
|
||||||
segments (split-stacktrace stacktrace verbose?)
|
segments (split-stacktrace stacktrace debug)
|
||||||
[fst snd] segments]
|
[fst snd] segments]
|
||||||
(run! println fst)
|
(run! println fst)
|
||||||
(when snd
|
(when snd
|
||||||
(println "...")
|
(println "... (run with --debug to see elided elements)")
|
||||||
(run! println snd))))
|
(run! println snd))))
|
||||||
|
|
||||||
(defn error-context [ex opts]
|
(defn error-context [ex opts]
|
||||||
(let [{:keys [:file :line :column]} (ex-data ex)]
|
(let [{:keys [:file :line :column]} (ex-data ex)]
|
||||||
(when (and file line)
|
(when (and file line column)
|
||||||
(when-let [content (case file
|
(when-let [content (case file
|
||||||
"<expr>" (:expression opts)
|
"<expr>" (:expression opts)
|
||||||
"<preloads>" (:preloads opts)
|
"<preloads>" (:preloads opts)
|
||||||
|
|
@ -81,6 +81,21 @@
|
||||||
(when (some :macro stacktrace)
|
(when (some :macro stacktrace)
|
||||||
"macroexpand")))
|
"macroexpand")))
|
||||||
|
|
||||||
|
(defn render-native-sym [sym]
|
||||||
|
(let [sym (-> (str sym)
|
||||||
|
(clojure.lang.Compiler/demunge)
|
||||||
|
symbol)
|
||||||
|
ns (namespace sym)]
|
||||||
|
(when ns
|
||||||
|
(let [ns (symbol ns)
|
||||||
|
nm (symbol (name sym))]
|
||||||
|
{:ns ns
|
||||||
|
:name nm
|
||||||
|
:sci/built-in true}))))
|
||||||
|
|
||||||
|
(defn render-native-stacktrace-elem [[sym _ _file _line]]
|
||||||
|
(render-native-sym sym))
|
||||||
|
|
||||||
(defn error-handler [^Exception e opts]
|
(defn error-handler [^Exception e opts]
|
||||||
(binding [*out* *err*]
|
(binding [*out* *err*]
|
||||||
(let [d (ex-data e)
|
(let [d (ex-data e)
|
||||||
|
|
@ -90,7 +105,12 @@
|
||||||
ex-name (when sci-error?
|
ex-name (when sci-error?
|
||||||
(some-> ^Throwable (ex-cause e)
|
(some-> ^Throwable (ex-cause e)
|
||||||
.getClass .getName))
|
.getClass .getName))
|
||||||
stacktrace (sci/stacktrace e)]
|
stacktrace (dedupe
|
||||||
|
(concat (sequence (comp (map StackTraceElement->vec)
|
||||||
|
(take-while #(not (str/starts-with? (first %) "sci.impl.")))
|
||||||
|
(map render-native-stacktrace-elem))
|
||||||
|
(.getStackTrace (or (ex-cause e) e)))
|
||||||
|
(sci/stacktrace e)))]
|
||||||
(if exit-code
|
(if exit-code
|
||||||
(do
|
(do
|
||||||
(when-let [m (.getMessage e)]
|
(when-let [m (.getMessage e)]
|
||||||
|
|
|
||||||
|
|
@ -248,3 +248,10 @@ user - <expr>:1:45
|
||||||
----- Exception ----------------------------------------------------------------
|
----- Exception ----------------------------------------------------------------
|
||||||
clojure.lang.ExceptionInfo: null
|
clojure.lang.ExceptionInfo: null
|
||||||
{:type :sci/error, :line 1, :column 19,")))))
|
{:type :sci/error, :line 1, :column 19,")))))
|
||||||
|
|
||||||
|
(deftest native-stacktrace-test
|
||||||
|
(let [output (try (tu/bb nil "(merge 1 2 3)")
|
||||||
|
(is false)
|
||||||
|
(catch Exception e (ex-message e)))]
|
||||||
|
(is (str/includes? (tu/normalize output)
|
||||||
|
"clojure.core/reduce1 - <built-in>"))))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue