Skip to content

Commit 1fc12f1

Browse files
authored
Merge pull request #158 from clj-commons/hls/20251003-traditional-option
Add :traditional option when printing / formatting exceptions
2 parents 308d1a0 + 30a0bf9 commit 1fc12f1

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

CHANGES.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 3.6.7 -- UNRELEASED
2+
3+
Adderd a :traditional option when printing or formatting exceptions.
4+
15
## 3.6.6 -- 30 Sep 2025
26

37
Improved `clj-commons.format.exceptions/parse-exception` to deal with exception text changes

src/clj_commons/format/exceptions.clj

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,13 @@
642642
(defn- render-exception
643643
[exception-stack options]
644644
(let [{show-properties? :properties
645-
:or {show-properties? true}} options
645+
:keys [traditional]
646+
:or {show-properties? true
647+
traditional *traditional*}} options
646648
exception-font (:exception *fonts*)
647649
message-font (:message *fonts*)
648650
property-font (:property *fonts*)
649-
modern? (not *traditional*)
651+
modern? (not traditional)
650652
max-class-name-width (max-from exception-stack #(-> % :class-name length))
651653
message-indent (+ 2 max-class-name-width)
652654
exception-f (fn [{:keys [class-name message properties]}]
@@ -678,7 +680,7 @@
678680
"\n")
679681
root-stack-trace (-> exception-stack last :stack-trace)]
680682
(list
681-
(when *traditional*
683+
(when traditional
682684
exceptions)
683685

684686
(build-stack-trace-output root-stack-trace modern?)
@@ -707,18 +709,20 @@
707709
:filter | The stack frame filter, which defaults to [[*default-stack-frame-filter*]]
708710
:properties | If true (the default) then properties of exceptions will be output
709711
:frame-limit | If non-nil, the number of stack frames to keep when outputting the stack trace of the deepest exception
712+
:traditional | If true, the use the traditional Java ordering of stack frames.
713+
714+
Output may be traditional or modern, as controlled by the :traditonal option
715+
(which defaults to the value of [[*traditional*]]).
710716
711-
Output may be traditional or modern, as controlled by [[*traditional*]].
712717
Traditional is the typical output order for Java: the stack of exceptions comes first (outermost to
713718
innermost) followed by the stack trace of the innermost exception, with the frames
714719
in order from deepest to most shallow.
715720
716-
Modern output is more readable; the stack trace comes first and is reversed: shallowest frame to most deep.
721+
Modern output is the default: the stack trace comes first and is reversed: shallowest frame to most deep.
717722
Then the exception stack is output, from the root exception to the outermost exception.
718723
The modern output order is more readable, as it puts the most useful information together at the bottom, so that
719-
it is not necessary to scroll back to see, for example, where the exception occurred.
720-
721-
The default is modern.
724+
it is not necessary to scroll back to see, for example, where the exception occurred, and more sensible,
725+
since it reflects a chronological order.
722726
723727
The stack frame filter is passed the map detailing each stack frame
724728
in the stack trace, and must return one of the following values:

test/clj_commons/exception_test.clj

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -605,14 +605,16 @@ failed with ABC123"
605605
(set frame-names)))))
606606

607607
(defn parse-and-format
608-
[file]
609-
(binding [*color-enabled* false]
610-
(-> file
611-
io/resource
612-
slurp
613-
(parse-exception nil)
614-
(f/format-exception* nil)
615-
string/split-lines)))
608+
([file]
609+
(parse-and-format file nil))
610+
([file options]
611+
(binding [*color-enabled* false]
612+
(-> file
613+
io/resource
614+
slurp
615+
(parse-exception options)
616+
(f/format-exception* options)
617+
string/split-lines))))
616618

617619
(deftest parse-no-message-exception
618620
(is (match? ["user/x REPL Input ┐ (repeats 255 times)"
@@ -622,6 +624,15 @@ failed with ABC123"
622624
"java.lang.StackOverflowError:"]
623625
(parse-and-format "overflow-exception.txt"))))
624626

627+
(deftest parse-no-message-exception-traditional
628+
(is (match? ["java.lang.StackOverflowError:"
629+
""
630+
" ..."
631+
"user/x REPL Input ┐ (repeats 255 times)"
632+
"user/y REPL Input ┘"
633+
"user/x REPL Input"]
634+
(parse-and-format "overflow-exception.txt" {:traditional true}))))
635+
625636
(deftest parse-nested-exception
626637

627638
(is (match? [" ..."

0 commit comments

Comments
 (0)