Skip to content

Commit

Permalink
Add ability to omit exception properties
Browse files Browse the repository at this point in the history
Fixes #23
  • Loading branch information
hlship committed Feb 20, 2014
1 parent 69dfe76 commit 5234f5b
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/io/aviso/exception.clj
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,9 @@
The *fonts* var contains ANSI definitions for how fonts are displayed; bind it to nil to remove ANSI formatting entirely."
([exception] (write-exception *out* exception))
([writer exception & {:keys [frame-limit]}]
([writer exception & {show-properties? :properties
frame-limit :frame-limit
:or {show-properties? true}}]
(let [exception-font (:exception *fonts*)
message-font (:message *fonts*)
property-font (:property *fonts*)
Expand All @@ -241,22 +243,23 @@
(doseq [e exception-stack]
(let [^Throwable exception (-> e :exception)
class-name (:name e)
message (.getMessage exception)
properties (update-keys (:properties e) name)
prop-keys (keys properties)
;; Allow for the width of the exception class name, and some extra
;; indentation.
property-formatter (c/format-columns " "
[:right (c/max-length prop-keys)]
": "
:none)]
message (.getMessage exception)]
(exception-formatter writer
(str exception-font class-name reset-font)
(str message-font message reset-font))
(doseq [k (sort prop-keys)]
(property-formatter writer
(str property-font k reset-font)
(-> properties (get k) format-property-value)))
(when show-properties?
(let [properties (update-keys (:properties e) name)
prop-keys (keys properties)
;; Allow for the width of the exception class name, and some extra
;; indentation.
property-formatter (c/format-columns " "
[:right (c/max-length prop-keys)]
": "
:none)]
(doseq [k (sort prop-keys)]
(property-formatter writer
(str property-font k reset-font)
(-> properties (get k) format-property-value)))))
(if (:root e)
(write-stack-trace writer exception frame-limit)))))))

Expand Down

0 comments on commit 5234f5b

Please sign in to comment.