Back
print-cause-trace (clj)
(source)function
(print-cause-trace tr)
(print-cause-trace tr n)
Like print-stack-trace but prints chained exceptions (causes).
Examples
clojure/core.typed
(deftest e-test
(is-tc-e #(e) [-> Any]
:requires [[clojure.stacktrace :refer [e]]]))
(deftest print-cause-trace-test
(is-tc-e #(print-cause-trace (Exception. "a")) [-> Any]
:requires [[clojure.stacktrace :refer [print-cause-trace]]])
(is-tc-err #(print-cause-trace "A") [-> Any]
:requires [[clojure.stacktrace :refer [print-cause-trace]]]))
puppetlabs/trapperkeeper
(ns puppetlabs.trapperkeeper.logging-test
(:require [clojure.java.io :as io]
clojure.stacktrace
[clojure.test :refer :all]
[clojure.tools.logging :as log]
[puppetlabs.trapperkeeper.logging :as tk-logging]
[puppetlabs.trapperkeeper.testutils.logging :refer :all]
[schema.test :as schema-test])
(:import (ch.qos.logback.classic Level)))
(deftest test-catch-all-logger
(testing "catch-all-logger ensures that message from an exception is logged"
(with-test-logging
;; Prevent the stacktrace from being printed out
(with-redefs [clojure.stacktrace/print-cause-trace (fn [_e] nil)]
(tk-logging/catch-all-logger
(Exception. "This exception is expected; testing error logging")
"this is my error message"))
(is (logged? #"this is my error message" :error)))))
typedclojure/typedclojure
(deftest e-test
(is-tc-e #(e) [-> t/Any]
:requires [[clojure.stacktrace :refer [e]]]))
(deftest print-cause-trace-test
(is-tc-e #(print-cause-trace (Exception. "a")) [-> t/Any]
:requires [[clojure.stacktrace :refer [print-cause-trace]]])
(is-tc-err #(print-cause-trace "A") [-> t/Any]
:requires [[clojure.stacktrace :refer [print-cause-trace]]]))
clj-commons/useful
;; leave out of ns decl so we can load with classlojure.io/resource-forms
(require '[clojure.pprint :as p])
(require '[clojure.stacktrace :as s])
(letfn [(interrogate-form [list-head form]
`(let [display# (fn [val#]
(let [form# (with-out-str
(clojure.pprint/with-pprint-dispatch
clojure.pprint/code-dispatch
(clojure.pprint/pprint '~form)))
val# (with-out-str (clojure.pprint/pprint val#))]
(~@list-head
(if (every? (partial > clojure.pprint/*print-miser-width*)
[(count form#) (count val#)])
(str (subs form# 0 (dec (count form#))) " is " val#)
(str form# "--------- is ---------\n" val#)))))]
(try (doto ~form display#)
(catch Throwable t#
(display# {:thrown t#
:trace (with-out-str
(clojure.stacktrace/print-cause-trace t#))})
(throw t#)))))]
epiccastle/spire
(ns spire.namespaces
(:require [spire.ssh :as ssh]
[spire.utils :as utils]
[spire.context :as context]
[spire.transport :as transport]
[spire.state :as state]
[spire.output.core]
[spire.output.default]
[spire.output.events]
[spire.output.quiet]
[spire.facts :as facts]
[spire.selmer :as selmer]
[spire.module.curl :as curl]
[spire.module.line-in-file :as line-in-file]
[spire.module.get-file :as get-file]
[spire.module.download :as download]
[spire.module.upload :as upload]
[spire.module.user :as user]
[spire.module.apt :as apt]
[spire.module.aws :as aws]
[spire.module.attrs :as attrs]
[spire.module.apt-repo :as apt-repo]
[spire.module.apt-key :as apt-key]
[spire.module.pkg :as pkg]
[spire.module.rm :as rm]
[spire.module.group :as group]
[spire.module.mkdir :as mkdir]
[spire.module.shell :as shell]
[spire.module.sysctl :as sysctl]
[spire.module.service :as service]
[spire.module.authorized-keys :as authorized-keys]
[spire.module.stat :as stat]
[spire.module.sudo :as sudo]
[spire.local]
[spire.remote]
[spire.default]
[clojure.tools.cli]
[clojure.java.shell]
[clojure.edn]
[clojure.stacktrace :as stacktrace]
[clojure.string]
[clojure.set]
[clojure.java.io]
[clojure.data.json]
[sci.core :as sci]
[clj-http.lite.core]
[clj-http.lite.client]
[clj-http.lite.links]
[clj-http.lite.util]
[cheshire.core]
[cheshire.custom]
[cheshire.exact]
[cheshire.experimental]
[cheshire.factory]
[cheshire.generate]
[cheshire.generate-seq]
[cheshire.parse]
[fipp.edn]
[edamame.core]
[spire.sci :refer [make-sci-bindings
make-sci-bindings-clean
sci-bind-macro
clojure-repl]]
[sci.impl.namespaces :refer [copy-var]]
[sci.impl.vars :as vars]))
(def namespaces
{
'clojure.core {'slurp slurp
'spit spit
'future (with-meta @#'clojure.core/future {:sci/macro true})
'future-call clojure.core/future-call
'*in* (sci/new-dynamic-var '*in* *in*)
'*out* (sci/new-dynamic-var '*out* *out*)
'*err* (sci/new-dynamic-var '*err* *err*)
}
'clojure.main {'repl-requires
'[[clojure.repl :refer [dir doc]]
[clojure.pprint :refer [pprint]]
[spire.default :refer [push-ssh! set-ssh!
push-local! set-local!
pop! empty!]]]}
'clojure.pprint (make-sci-bindings fipp.edn)
'clojure.repl clojure-repl
'clojure.stacktrace {'root-cause stacktrace/root-cause
'print-trace-element (redirect-out-to-sci stacktrace/print-trace-element)
'print-throwable (redirect-out-to-sci stacktrace/print-throwable)
'print-stack-trace (redirect-out-to-sci stacktrace/print-stack-trace)
'print-cause-trace (redirect-out-to-sci stacktrace/print-cause-trace)}