|
3 | 3 | errors/exceptions that might arise from doing so."
|
4 | 4 | (:refer-clojure :exclude [error-handler])
|
5 | 5 | (:require
|
| 6 | + [clojure.main] |
6 | 7 | [clojure.set :as set]
|
| 8 | + [clojure.stacktrace] |
7 | 9 | [clojure.walk :as walk]
|
8 | 10 | [nrepl.middleware.caught :as caught]
|
9 | 11 | [nrepl.middleware.print :as print]
|
10 | 12 | [nrepl.misc :refer [response-for]]
|
11 |
| - [nrepl.transport :as transport]) |
| 13 | + [nrepl.transport :as transport] |
| 14 | + [orchard.stacktrace :as stacktrace]) |
12 | 15 | (:import
|
13 | 16 | java.io.InputStream
|
14 | 17 | clojure.lang.RT
|
15 | 18 | (nrepl.transport Transport)))
|
16 | 19 |
|
17 |
| -(def ^:private print-cause-trace |
18 |
| - (delay |
19 |
| - (requiring-resolve 'clojure.stacktrace/print-cause-trace))) |
20 |
| - |
21 |
| -(def ^:private analyze-causes |
22 |
| - (delay |
23 |
| - (requiring-resolve 'orchard.stacktrace/analyze))) |
24 |
| - |
25 | 20 | ;;; UTILITY FUNCTIONS
|
26 | 21 |
|
27 |
| -(defn error-summary |
28 |
| - "Takes a `java.lang.Exception` as `ex` and returns a map summarizing |
29 |
| - the exception. If present, the varargs are converted to a set and |
30 |
| - used as the value for the :status key." |
31 |
| - [ex & statuses] |
32 |
| - (merge {:ex (str (class ex)) |
33 |
| - :err (with-out-str (@print-cause-trace ex)) |
34 |
| - :root-ex (-> (#'clojure.main/root-cause ex) class str)} |
35 |
| - (when statuses {:status (set statuses)}))) |
36 |
| - |
37 |
| -(defn pp-stacktrace |
38 |
| - "Takes a `java.lang.Exception` as `ex` and a pretty-print function |
39 |
| - as `print-fn`, then returns a pretty-printed version of the |
40 |
| - exception that can be rendered by CIDER's stacktrace viewer." |
41 |
| - [ex print-fn] |
42 |
| - {:pp-stacktrace (@analyze-causes ex print-fn)}) |
43 |
| - |
44 | 22 | (defn base-error-response
|
45 | 23 | "Takes a CIDER-nREPL message as `msg`, an Exception `ex`, and a
|
46 | 24 | non-collection vararg of `statuses`. This will return the standard
|
47 | 25 | response for CIDER-nREPL sync-op errors that can be rendered by
|
48 | 26 | CIDER's stacktrace viewer. N.B., statuses such as `:done` and
|
49 | 27 | `:<op-name>-error` are NOT automatically added"
|
50 | 28 | [msg ex & statuses]
|
51 |
| - (response-for msg (merge (apply error-summary ex statuses) |
52 |
| - (pp-stacktrace ex (::print/print-fn msg))))) |
| 29 | + (response-for |
| 30 | + msg (merge {:ex (str (class ex)) |
| 31 | + :err (with-out-str (clojure.stacktrace/print-cause-trace ex)) |
| 32 | + :root-ex (str (class (clojure.main/root-cause ex))) |
| 33 | + :pp-stacktrace (stacktrace/analyze ex)} |
| 34 | + (when statuses {:status (set statuses)})))) |
53 | 35 |
|
54 | 36 | (defn- normalize-status
|
55 | 37 | "Accepts various representations of an nREPL reply message's status
|
|
0 commit comments