Skip to content

Commit 1bd1f45

Browse files
Replace all haystack.analyzer usage with orchard.stacktrace
1 parent 8c5ac21 commit 1bd1f45

File tree

8 files changed

+37
-54
lines changed

8 files changed

+37
-54
lines changed

project.clj

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
:url "http://www.eclipse.org/legal/epl-v10.html"}
2222
:scm {:name "git" :url "https://github.com/clojure-emacs/cider-nrepl"}
2323
:dependencies [[nrepl/nrepl "1.3.1" :exclusions [org.clojure/clojure]]
24-
[cider/orchard "0.30.1" :exclusions [org.clojure/clojure]]
25-
^:inline-dep [mx.cider/haystack "0.3.3" :exclusions [cider/orchard]]
24+
[cider/orchard "0.31.0" :exclusions [org.clojure/clojure]]
2625
^:inline-dep [thunknyc/profile "0.5.2"]
2726
^:inline-dep [mvxcvi/puget "1.3.4" :exclusions [org.clojure/clojure]]
2827
^:inline-dep [fipp ~fipp-version] ; can be removed in unresolved-tree mode

src/cider/nrepl.clj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
[cider.nrepl.middleware.util.cljs :as cljs]
1313
[cider.nrepl.print-method] ;; we load this namespace, so it's directly available to clients
1414
[compliment.core :as compliment]
15-
[haystack.analyzer :as analyzer]
1615
[nrepl.middleware :refer [set-descriptor!]]
1716
[nrepl.middleware.caught :refer [wrap-caught]]
1817
[nrepl.middleware.print :refer [wrap-print wrap-print-optional-arguments]]
@@ -50,7 +49,6 @@
5049
;; shipped with Orchard.
5150
(try (orchard.java/source-info 'mx.cider.orchard.LruMap)
5251
(catch Exception _))
53-
@analyzer/spec-abbrev
5452

5553
(defn warmup-caches!
5654
"Warm up some of the dependency caches to improve UX performance for first hits.

src/cider/nrepl/middleware/debug.clj

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
[cider.nrepl.middleware.util.cljs :as cljs]
88
[cider.nrepl.middleware.util.instrument :as ins]
99
[cider.nrepl.middleware.util.nrepl :refer [notify-client]]
10-
[haystack.analyzer :as stacktrace.analyzer]
1110
[nrepl.middleware.interruptible-eval :refer [*msg*]]
1211
[nrepl.middleware.print :as print]
1312
[nrepl.misc :refer [response-for]]
1413
[nrepl.transport :as transport]
1514
[orchard.info :as info]
1615
[orchard.inspect :as inspect]
1716
[orchard.meta :as m]
18-
[orchard.print])
17+
[orchard.print]
18+
[orchard.stacktrace :as stacktrace])
1919
(:import
2020
[clojure.lang Compiler$LocalBinding]
2121
[java.util UUID]))
@@ -219,7 +219,7 @@ this map (identified by a key), and will `dissoc` it afterwards."}
219219
(when-not (instance? ThreadDeath root-ex#)
220220
(debugger-send
221221
{:status :eval-error
222-
:causes [(let [causes# (stacktrace.analyzer/analyze e# (::print/print-fn *msg*))]
222+
:causes [(let [causes# (stacktrace/analyze e# (::print/print-fn *msg*))]
223223
(when (coll? causes#) (last causes#)))]})))
224224
error#))]
225225
(if (= error# ~sym)
@@ -291,11 +291,11 @@ this map (identified by a key), and will `dissoc` it afterwards."}
291291
(debugger-send
292292
{:status :stack
293293
:causes (if (instance? Throwable value)
294-
(stacktrace.analyzer/analyze value (::print/print-fn *msg*))
294+
(stacktrace/analyze value (::print/print-fn *msg*))
295295
[{:class "StackTrace"
296296
:message "Harmless user-requested stacktrace"
297297
:stacktrace (-> (Exception. "Dummy")
298-
(stacktrace.analyzer/analyze (::print/print-fn *msg*))
298+
(stacktrace/analyze (::print/print-fn *msg*))
299299
last :stacktrace)}])}))
300300

301301
(def debug-commands

src/cider/nrepl/middleware/reload.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
[clj-reload.core :as reload]
88
[clojure.main :refer [repl-caught]]
99
[clojure.string :as str]
10-
[haystack.analyzer :as analyzer]
1110
[nrepl.middleware.interruptible-eval :refer [*msg*]]
1211
[nrepl.middleware.print :as print]
1312
[nrepl.misc :refer [response-for]]
14-
[nrepl.transport :as transport]))
13+
[nrepl.transport :as transport]
14+
[orchard.stacktrace :as stacktrace]))
1515

1616
(defn- user-reload
1717
"Resolve clj-reload.core/<sym> from the user project or return fallback."
@@ -56,7 +56,7 @@
5656
(respond msg {:status :ok}))
5757
(catch Throwable error
5858
(respond msg {:status :error
59-
:error (analyzer/analyze error print-fn)})
59+
:error (stacktrace/analyze error print-fn)})
6060
(binding [*msg* msg
6161
*err* (print/replying-PrintWriter :err msg {})]
6262
(repl-caught error)))))

src/cider/nrepl/middleware/stacktrace.clj

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
"Cause and stacktrace analysis for exceptions"
33
{:author "Jeff Valk"}
44
(:require
5+
[cider.nrepl.middleware.inspect :as middleware.inspect]
56
[cider.nrepl.middleware.util.nrepl :refer [notify-client]]
6-
[clojure.string :as str]
7-
[haystack.analyzer :as analyzer]
87
[nrepl.middleware.print :as print]
9-
[cider.nrepl.middleware.inspect :as middleware.inspect]
108
[nrepl.misc :refer [response-for]]
11-
[nrepl.transport :as t]))
9+
[nrepl.transport :as t]
10+
[orchard.stacktrace :as stacktrace]))
1211

1312
(defn- done
1413
"Send the done response to the client."
@@ -35,12 +34,12 @@
3534
[{:keys [session ::print/print-fn] :as msg}]
3635
(let [last-exception (@session #'*e)]
3736
(swap! session assoc #'*last-exception* last-exception) ;; note that *e can change later, so this entry isn't redundant
38-
(send-analysis msg (analyzer/analyze last-exception print-fn))))
37+
(send-analysis msg (stacktrace/analyze last-exception print-fn))))
3938

4039
(defn- handle-analyze-last-stacktrace-op
4140
"Handle the analyze last stacktrace op."
4241
[{:keys [session] :as msg}]
43-
(if (and session (@session #'*e))
42+
(if (@session #'*e)
4443
(analyze-last-stacktrace msg)
4544
(no-error msg))
4645
(done msg))
@@ -53,17 +52,12 @@
5352
(handle-analyze-last-stacktrace-op msg)
5453
(notify-client msg "The `stacktrace` op is deprecated, please use `analyze-last-stacktrace` instead." :warning))
5554

56-
(defn handle-inspect-last-exception-op [{:keys [index transport] :as msg}]
57-
(let [le (when index
58-
(some-> msg :session deref (get #'*last-exception*)))
59-
cause (when le
60-
(loop [n 0
61-
cause le]
62-
(if (= n index)
63-
cause
64-
(when cause
65-
(recur (inc n)
66-
(some-> ^Throwable cause .getCause))))))]
55+
(defn handle-inspect-last-exception-op [{:keys [session index transport] :as msg}]
56+
(let [last-exception (@session #'*last-exception*)
57+
causes (->> (iterate #(.getCause ^Throwable %) last-exception)
58+
(take-while some?))
59+
cause (when index
60+
(nth causes index nil))]
6761
(if cause
6862
(t/send transport (middleware.inspect/inspect-reply* msg cause))
6963
(no-error msg))

src/cider/nrepl/middleware/test.clj

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@
99
[clojure.string :as str]
1010
[clojure.test :as test]
1111
[clojure.walk :as walk]
12-
[haystack.analyzer :as stacktrace.analyzer]
13-
[haystack.parser.clojure.throwable :as throwable]
1412
[nrepl.middleware.interruptible-eval :as ie]
1513
[nrepl.middleware.print :as print]
1614
[nrepl.misc :refer [response-for]]
1715
[nrepl.transport :as t]
1816
[orchard.misc :as misc]
19-
[orchard.query :as query]))
17+
[orchard.query :as query]
18+
[orchard.stacktrace :as stacktrace]))
2019

2120
;;; ## Overview
2221
;;
@@ -66,19 +65,14 @@
6665
(defn stack-frame
6766
"Search the stacktrace of exception `e` for the function `f` and return info
6867
describing the stack frame, including var, class, and line."
69-
([^Exception e f]
70-
(stack-frame (stacktrace.analyzer/directory-namespaces) e f))
71-
([namespaces ^Exception e f]
72-
(when-let [class-name (some-> f class .getName)]
73-
(->> e
74-
.getStackTrace
75-
(map throwable/StackTraceElement->vec)
76-
(map (partial stacktrace.analyzer/analyze-frame namespaces))
77-
(filter
78-
#(when-let [frame-cname (:class %)]
79-
(when (string? frame-cname)
80-
(str/starts-with? frame-cname class-name))))
81-
first))))
68+
[^Exception e f]
69+
(when-let [class-name (some-> f class .getName)]
70+
(when-let [analyzed-trace (:stacktrace (first (stacktrace/analyze e)))]
71+
(some #(when-let [frame-cname (:class %)]
72+
(when (and (string? frame-cname)
73+
(str/starts-with? frame-cname class-name))
74+
%))
75+
analyzed-trace))))
8276

8377
(defn- print-object
8478
"Print `object` using println for matcher-combinators results and pprint
@@ -260,11 +254,9 @@
260254
finds the erring test fixture in the stacktrace and binds it as the current
261255
test var. Test count is decremented to indicate that no tests were run."
262256
[ns e]
263-
(let [namespaces (stacktrace.analyzer/directory-namespaces)
264-
frame (->> (concat (:clojure.test/once-fixtures (meta ns))
257+
(let [frame (->> (concat (:clojure.test/once-fixtures (meta ns))
265258
(:clojure.test/each-fixtures (meta ns)))
266-
(map (partial stack-frame namespaces e))
267-
(filter identity)
259+
(keep #(stack-frame e %))
268260
(first))
269261
fixture (resolve (symbol (:var frame)))]
270262
(swap! current-report update-in [:summary :test] dec)
@@ -491,7 +483,7 @@
491483
(with-bindings (assoc @session #'ie/*msg* msg)
492484
(let [[ns var] (map misc/as-sym [ns var])]
493485
(if-let [e (get-in @results [ns var index :error])]
494-
(doseq [cause (stacktrace.analyzer/analyze e print-fn)]
486+
(doseq [cause (stacktrace/analyze e print-fn)]
495487
(t/send transport (response-for msg cause)))
496488
(t/send transport (response-for msg :status :no-error))))))
497489
(fn []

src/cider/nrepl/middleware/util/error_handling.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
(def ^:private analyze-causes
2222
(delay
23-
(requiring-resolve 'haystack.analyzer/analyze)))
23+
(requiring-resolve 'orchard.stacktrace/analyze)))
2424

2525
;;; UTILITY FUNCTIONS
2626

src/cider/nrepl/middleware/util/reload.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
{:added "0.47.0"}
44
(:require
55
[clojure.main :refer [repl-caught]]
6-
[haystack.analyzer :as stacktrace.analyzer]
76
[nrepl.middleware.interruptible-eval :refer [*msg*]]
87
[nrepl.middleware.print :as print]
98
[nrepl.misc :refer [response-for]]
109
[nrepl.transport :as transport]
11-
[orchard.misc :as misc]))
10+
[orchard.misc :as misc]
11+
[orchard.stacktrace :as stacktrace]))
1212

1313
(defn error-reply
1414
[{:keys [error error-ns]}
@@ -17,7 +17,7 @@
1717
(transport/send
1818
transport
1919
(response-for msg (cond-> {:status :error}
20-
error (assoc :error (stacktrace.analyzer/analyze error print-fn))
20+
error (assoc :error (stacktrace/analyze error print-fn))
2121
error-ns (assoc :error-ns error-ns))))
2222

2323
(binding [*msg* msg

0 commit comments

Comments
 (0)