Skip to content

Commit 58c4abc

Browse files
committed
Demangle the names of reified protocol methods
Fixes #4
1 parent d186699 commit 58c4abc

File tree

2 files changed

+29
-14
lines changed

2 files changed

+29
-14
lines changed

src/io/aviso/exception.clj

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -131,37 +131,43 @@
131131
(into {} (map (fn [[k v]] [(f k) v]) m)))
132132

133133
(defn- convert-to-clojure
134-
[class-name]
134+
[class-name method-name]
135135
(let [[namespace-name & raw-function-ids] (str/split class-name #"\$")
136136
;; Clojure adds __1234 unique ids to the ends of things, remove those.
137-
function-ids (map #(str/replace % #"__\d+" "") raw-function-ids)]
137+
function-ids (map #(str/replace % #"__\d+" "") raw-function-ids)
138+
;; In a degenerate case, a protocol method could be called "invoke" or "doInvoke"; we're ignoring
139+
;; that possibility here and assuming it's the IFn.invoke() or doInvoke().
140+
all-ids (if (contains? #{"invoke" "doInvoke"} method-name)
141+
function-ids
142+
(-> function-ids vec (conj method-name)))]
138143
;; The assumption is that no real namespace or function name will contain underscores (the underscores
139144
;; are name-mangled dashes).
140-
(->> (cons namespace-name function-ids) (map demangle))))
145+
(->>
146+
(cons namespace-name all-ids)
147+
(map demangle))))
141148

142149
(defn- expand-stack-trace-element
143150
[^StackTraceElement element]
144151
(let [class-name (.getClassName element)
145152
method-name (.getMethodName element)
146153
dotx (.lastIndexOf class-name ".")
147154
file-name (or (.getFileName element) "")
148-
is-clojure? (and (.endsWith file-name ".clj")
149-
(contains? #{"invoke" "doInvoke"} method-name))
150-
names (if is-clojure? (convert-to-clojure class-name) [])
155+
is-clojure? (.endsWith file-name ".clj")
156+
names (if is-clojure? (convert-to-clojure class-name method-name) [])
151157
name (str/join "/" names)
152158
line (-> element .getLineNumber)]
153-
{:file file-name
154-
:line (if (pos? line) line)
155-
:class class-name
156-
:package (if (pos? dotx) (.substring class-name 0 dotx))
159+
{:file file-name
160+
:line (if (pos? line) line)
161+
:class class-name
162+
:package (if (pos? dotx) (.substring class-name 0 dotx))
157163
:simple-class (if (pos? dotx)
158164
(.substring class-name (inc dotx))
159165
class-name)
160-
:method method-name
166+
:method method-name
161167
;; Used to calculate column width
162-
:name name
168+
:name name
163169
;; Used to present compound name with last term highlighted
164-
:names names}))
170+
:names names}))
165171

166172
(def ^:private empty-stack-trace-warning
167173
"Stack trace of root exception is empty; this is likely due to a JVM optimization that can be disabled with -XX:-OmitStackTraceInFastThrow.")

test/user.clj

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,19 @@
77
[]
88
(throw (SQLException. "Database failure" "ABC" 123)))
99

10+
(defprotocol Worker
11+
(do-work [this]))
12+
13+
(defn make-jdbc-update-worker
14+
[]
15+
(reify
16+
Worker
17+
(do-work [this] (jdbc-update))))
18+
1019
(defn- update-row
1120
[]
1221
(try
13-
(jdbc-update)
22+
(-> (make-jdbc-update-worker) do-work)
1423
(catch Throwable e
1524
(throw (RuntimeException. "Failure updating row" e)))))
1625

0 commit comments

Comments
 (0)