Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 3.6.2 -- UNRELEASED

- Fix a bug where the horizontal bar for repeated stack frames could be misaligned
- Hide `clojure.lang.RestFn` stack frames

[Closed Issues](https://github.com/clj-commons/pretty/milestone/61?closed=1)

## 3.6.1 -- 4 Aug 2025

Fix a bug where omitted stack frames were printed.
Expand Down
Binary file modified docs/images/exception-repeat.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
57 changes: 31 additions & 26 deletions src/clj_commons/format/exceptions.clj
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,14 @@
The default rules:

* omit everything in `clojure.lang`, `java.lang.reflect`
* omit `clojure.core/with-bindings*` and `clojure.core/apply`
* hide `clojure.core/with-bindings*` and `clojure.core/apply`, `clojure.lang.RestFn`
* hide everything in `sun.reflect`
* omit a number of functions in `clojure.test`
* terminate at `speclj.*`, `clojure.main/.*`, or `nrepl.middleware.interruptible-eval`
"
[[:name "clojure.core/apply" :hide]
[:id #"\Qclojure.lang.AFn.applyTo\E(Helper)?.*" :hide]
[:id #"\Qclojure.lang.RestFn.\E.*" :hide]
[:package "clojure.lang" :omit]
[:name "clojure.core/with-bindings*" :hide]
[:package #"sun\.reflect.*" :hide]
Expand Down Expand Up @@ -382,7 +383,6 @@
dec)]
(assoc frame
:name-width width
:line (str line)
:name [(get *fonts* (clj-frame-font-key frame))
(->> names' drop-last (str/join "/"))
"/"
Expand All @@ -401,7 +401,7 @@

Formatting is based on whether the frame is omitted, and whether it is a Clojure or Java frame."
{:added "0.3.0"}
[{:keys [file line names repeats] :as frame}]
[{:keys [line names] :as frame}]
(cond
(:omitted frame)
(assoc frame
Expand All @@ -415,8 +415,7 @@
(let [full-name (str (:class frame) "." (:method frame))]
(assoc frame
:name [(:java-frame *fonts*) full-name]
:name-width (length full-name)
:line (str line)))
:name-width (length full-name)))

:else
(format-clojure-frame-base frame)))
Expand Down Expand Up @@ -536,29 +535,35 @@
max-name-width (max-from rows :name-width)
;; Allow for the colon in frames w/ a line number (this assumes there's at least one)
max-file-width (inc (max-from rows #(-> % :file length)))
max-line-width (max-from rows #(-> % :line length))
max-line-width (max-from rows #(-> % :line str length))
*lines (volatile! (transient []))
format-single-frame (fn [{:keys [name file line]} repeat-count frame-index frame-count]
(list
[{:width max-name-width} name]
" "
[{:width max-file-width
:font source-font} file]
(when line ":")
" "
[{:width max-line-width} line]
(when (> repeat-count 1)
(cond
(= frame-index 0)
(format " %s (repeats %,d times)"
(if (= 1 frame-count) "─" "┐")
repeat-count)

(= frame-index (dec frame-count))
" ┘"

:else
" │"))))]
(let [has-repeat? (> repeat-count 1)
show-line? (or line has-repeat?)
show-file? (or show-line? file)]
(list
[{:width max-name-width} name]
(when show-file?
(list
" "
[{:width max-file-width
:font source-font} file]
(when show-line?
(list
(if line ":" " ")
[{:width max-line-width} line]
(when (> repeat-count 1)
(cond
(= frame-index 0)
(format " %s (repeats %,d times)"
(if (= 1 frame-count) "─" "┐")
repeat-count)

(= frame-index (dec frame-count))
" ┘"

:else
" │")))))))))]
(doseq [[repeat-count frames] (repetitions :id rows)
[frame-index frame] (map-indexed vector frames)]
(vswap! *lines
Expand Down
22 changes: 0 additions & 22 deletions test/clj_commons/exception_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,6 @@
"tcp-client"]
:package "riemann"
:simple-class "client$tcp_client"}
{:class "clojure.lang.RestFn"
:file "RestFn.java"
:id "clojure.lang.RestFn.invoke:408"
:is-clojure? false
:line 408
:method "invoke"
:name ""
:names []
:omitted true
:package "clojure.lang"
:simple-class "RestFn"}
{:class "com.example.error_monitor$make_connection"
:file "error_monitor.clj"
:id "com.example.error-monitor/make-connection:22"
Expand Down Expand Up @@ -214,17 +203,6 @@
"-main"]
:package "com.example.error_monitor"
:simple-class "main$_main"}
{:class "clojure.lang.RestFn"
:file "RestFn.java"
:id "clojure.lang.RestFn.applyTo:137"
:is-clojure? false
:line 137
:method "applyTo"
:name ""
:names []
:omitted true
:package "clojure.lang"
:simple-class "RestFn"}
{:class "com.example.error_monitor.main"
:file ""
:id "com.example.error_monitor.main.main:-1"
Expand Down
8 changes: 4 additions & 4 deletions test/demo.clj
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@
(countdown (dec n))))

(defn nested-interloper
[f arg]
(f arg))
[f & arg]
(apply f arg))

(defn interloper
[f arg]
(nested-interloper f arg))
[& args]
(apply nested-interloper args))

(defn countdown-alt
[n]
Expand Down
Loading