Skip to content

Commit

Permalink
add 'caused by' info/stacktrace when printing exception
Browse files Browse the repository at this point in the history
  • Loading branch information
philomates committed Mar 16, 2017
1 parent 5c80966 commit 5009b1e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/midje/util/exceptions.clj
Expand Up @@ -35,6 +35,12 @@
(cons (str throwable)
(without-clojure-strings (stacktrace-as-strings throwable))))

(defn- friendly-caused-by [ex prefix]
(when-let [cause (.getCause ex)]
(let [[data & stacktrace] (friendly-exception-lines cause prefix)]
(cons (str line-separator prefix "Caused by: " data)
stacktrace))))


;; When a fact throws an Exception or Error it gets wrapped
;; in this deftype
Expand All @@ -47,7 +53,9 @@
ICapturedThrowable
(throwable [this] ex)
(friendly-stacktrace [this]
(join line-separator (friendly-exception-lines (throwable this) " "))))
(join line-separator
(concat (friendly-exception-lines (throwable this) " ")
(friendly-caused-by (throwable this) " ")))))

(defn captured-throwable [ex]
(CapturedThrowable. ex))
Expand Down

0 comments on commit 5009b1e

Please sign in to comment.