|
17 | 17 |
|
18 | 18 | ;; Analyze the last stacktrace
|
19 | 19 |
|
20 |
| -(def ^:dynamic *last-exception* nil) |
21 |
| - |
22 | 20 | (defn- analyze-last-stacktrace
|
23 | 21 | "Analyze the last exception."
|
24 | 22 | [{:keys [session] :as msg}]
|
25 | 23 | (let [last-exception (@session #'*e)]
|
26 |
| - (swap! session assoc #'*last-exception* last-exception) ;; note that *e can change later, so this entry isn't redundant |
| 24 | + ;; We need to remember the analyzed exception separately because we need to |
| 25 | + ;; provide a way to inspect it while *e can change. |
| 26 | + (alter-meta! session assoc ::analyzed-exception last-exception) |
27 | 27 | (send-analysis msg (stacktrace/analyze last-exception))))
|
28 | 28 |
|
29 | 29 | (defn- handle-analyze-last-stacktrace-op
|
|
42 | 42 | (handle-analyze-last-stacktrace-op msg)
|
43 | 43 | (notify-client msg "The `stacktrace` op is deprecated, please use `analyze-last-stacktrace` instead." :warning))
|
44 | 44 |
|
| 45 | +(defn- get-last-exception-cause [{:keys [session index] :as msg}] |
| 46 | + (when index |
| 47 | + (let [last-exception (::analyzed-exception (meta session)) |
| 48 | + causes (when last-exception |
| 49 | + (->> (iterate #(.getCause ^Throwable %) last-exception) |
| 50 | + (take-while some?)))] |
| 51 | + (nth causes index nil)))) |
| 52 | + |
45 | 53 | (defn handle-inspect-last-exception-op [{:keys [session index transport] :as msg}]
|
46 |
| - (let [last-exception (@session #'*last-exception*) |
47 |
| - causes (->> (iterate #(.getCause ^Throwable %) last-exception) |
48 |
| - (take-while some?)) |
49 |
| - cause (when index |
50 |
| - (nth causes index nil))] |
51 |
| - (if cause |
52 |
| - (t/send transport (middleware.inspect/inspect-reply* msg cause)) |
| 54 | + (let [inspect-ex-data? (= (:ex-data msg) "true") |
| 55 | + cause (get-last-exception-cause msg) |
| 56 | + object (if inspect-ex-data? |
| 57 | + (ex-data cause) |
| 58 | + cause)] |
| 59 | + (if object |
| 60 | + (t/send transport (middleware.inspect/inspect-reply* msg object)) |
53 | 61 | (respond-to msg :status :no-error))
|
54 | 62 | (respond-to msg :status :done)))
|
55 | 63 |
|
|
0 commit comments