From 5009b1eab002e778c94102baa7356f59aae385d3 Mon Sep 17 00:00:00 2001 From: Phillip Mates Date: Thu, 16 Mar 2017 17:14:51 -0300 Subject: [PATCH] add 'caused by' info/stacktrace when printing exception --- src/midje/util/exceptions.clj | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/midje/util/exceptions.clj b/src/midje/util/exceptions.clj index 5933d0444..fa66b39da 100644 --- a/src/midje/util/exceptions.clj +++ b/src/midje/util/exceptions.clj @@ -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 @@ -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))