Skip to content

Commit

Permalink
Compose the stack trace warning and only emit it once
Browse files Browse the repository at this point in the history
  • Loading branch information
hlship committed Jun 26, 2023
1 parent 5b1511d commit 397000d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/clj_commons/format/exceptions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,6 @@
;; Used to present compound Clojure name with last term highlighted
:names names}))

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


(defn- apply-frame-filter
[frame-filter frames]
(if (nil? frame-filter)
Expand Down Expand Up @@ -299,6 +295,15 @@
:else
(conj output-frames frame))))

(def ^:private stack-trace-warning
(delay
(binding [*out* *err*]
(println (compose
[:bright-yellow "WARNING: "]
"Stack trace of root exception is empty; this is likely due to a JVM optimization that can be disabled with "
[:bold "-XX:-OmitStackTraceInFastThrow" "."]))
(flush))))

(defn expand-stack-trace
"Extracts the stack trace for an exception and returns a seq of expanded stack frame maps:
Expand Down Expand Up @@ -336,9 +341,7 @@
[^Throwable exception]
(let [elements (map (partial expand-stack-trace-element current-dir-prefix) (.getStackTrace exception))]
(when (empty? elements)
(binding [*out* *err*]
(println empty-stack-trace-warning)
(flush)))
@stack-trace-warning)
elements))

(defn- clj-frame-font-key
Expand Down

0 comments on commit 397000d

Please sign in to comment.