WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 5145908

Browse files
committed
Merge in stack trace changes for Clojure 1.8+?
Fixes #4 Signed-off-by: Sean Corfield <[email protected]>
1 parent 00b1360 commit 5145908

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
## CHANGES
22

33
* v0.13.next in progress
4-
* address [clj-commons/slingshot#3](https://github.com/clj-commons/slingshot/issues/3) by merging `and` optimizations from original PR [#55](https://github.com/scgilardi/slingshot/pull/55) by [jbouwman](https://github.com/jbouwman).
4+
* address [clj-commons/slingshot#4](https://github.com/clj-commons/slingshot/issues/4) by merging stacktrace changes from [a20748f](https://github.com/clj-commons/slingshot/commit/a20748fd2d6d4a9020d296a3798e82f136e2bfe2) by [@scgilardi](https://github.com/scgilardi).
5+
* address [clj-commons/slingshot#3](https://github.com/clj-commons/slingshot/issues/3) by merging `and` optimizations from original PR [#55](https://github.com/scgilardi/slingshot/pull/55) by [@jbouwman](https://github.com/jbouwman).
56

67
* v0.13.0 -- 2025-09-20
78
- add clj-kondo config export

src/clj_commons/slingshot/support.clj

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,20 @@
204204
(defn stack-trace
205205
"Returns the current stack trace beginning at the caller's frame"
206206
[]
207-
(let [trace (.getStackTrace (Thread/currentThread))]
208-
(java.util.Arrays/copyOfRange trace 2 (alength trace))))
207+
(let [trace (.getStackTrace (Thread/currentThread))
208+
len (alength trace)
209+
limit (min (dec len) 4)
210+
offset (loop [offset 0]
211+
(if (> offset limit)
212+
0
213+
(let [^StackTraceElement element (aget trace offset)
214+
class-name (.getClassName element)]
215+
(if (or (= class-name "java.lang.Thread")
216+
(= class-name "slingshot.support$stack_trace"))
217+
(recur (inc offset))
218+
offset))))]
219+
(java.util.Arrays/copyOfRange ^"[Ljava.lang.StackTraceElement;" trace
220+
^int offset len)))
209221

210222
(defn parse-throw+
211223
"Returns a vector containing the message and cause that result from

test/clj_commons/slingshot/support_test.clj

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

5050
(deftest test-stack-trace
5151
(let [{:keys [methodName className]} (-> (stack-trace-fn) first bean)]
52-
(is (= methodName "invoke"))
52+
(is (re-find #"^invoke" methodName))
5353
(is (re-find #"stack_trace(_fn)?$" className))))
5454

5555
(deftest test-resolve-local

0 commit comments

Comments
 (0)