Back
print-stack-trace (clj)
(source)function
(print-stack-trace tr)
(print-stack-trace tr n)
Prints a Clojure-oriented stack trace of tr, a Throwable.
Prints a maximum of n stack frames (default: unlimited).
Does not print chained exceptions (causes).
Examples
clojure
(ns clojure.test-clojure.test
(:use clojure.test)
(:require [clojure.stacktrace :as stack]))
(deftest clj-1102-empty-stack-trace-should-not-throw-exceptions
(let [empty-stack (into-array (Class/forName "java.lang.StackTraceElement")
[])
t (doto (Exception.) (.setStackTrace empty-stack))]
(is (map? (#'clojure.test/file-and-line t 0)) "Should pass")
(is (map? (#'clojure.test/stacktrace-file-and-line empty-stack)) "Should pass")
(is (string? (with-out-str (stack/print-stack-trace t))) "Should pass")))
clojure/core.typed
(deftest e-test
(is-tc-e #(e) [-> Any]
:requires [[clojure.stacktrace :refer [e]]]))
(deftest print-stack-trace-test
(is-tc-e #(print-stack-trace (Exception. "a")) [-> Any]
:requires [[clojure.stacktrace :refer [print-stack-trace]]])
(is-tc-err #(print-stack-trace "AC") [-> Any]
:requires [[clojure.stacktrace :refer [print-stack-trace]]]))
typedclojure/typedclojure
(deftest e-test
(is-tc-e #(e) [-> t/Any]
:requires [[clojure.stacktrace :refer [e]]]))
(deftest print-stack-trace-test
(is-tc-e #(print-stack-trace (Exception. "a")) [-> t/Any]
:requires [[clojure.stacktrace :refer [print-stack-trace]]])
(is-tc-err #(print-stack-trace "AC") [-> t/Any]
:requires [[clojure.stacktrace :refer [print-stack-trace]]]))
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)}
pedestal/pedestal-app
(require 'clojure.stacktrace)
;; Attempt to load app-tools.dev namespace, catch any exceptions so that REPL
;; does not fail to start
(defonce app-tools-initialized
(try
(use 'io.pedestal.app-tools.dev)
true
(catch Throwable t
(println "ERROR: There was a problem loading io.pedestal.app-tools.dev")
(clojure.stacktrace/print-stack-trace t)
(println))))
palletops/log-config
(ns com.palletops.log-config.tools-logging
(:require
[clojure.stacktrace :as stacktrace]
[clojure.tools.logging :as logging]))
;;; A stdout logger
;;; Logs everyting to stdout. Can be useful to test logging.
(deftype StdoutLogger
[]
clojure.tools.logging.impl.Logger
(enabled? [log level] true)
(write! [log level throwable message]
(println (name level) message)
(when throwable
(stacktrace/print-stack-trace
(stacktrace/root-cause throwable)))))
(def stdout-log (delay (StdoutLogger.)))