Created
February 11, 2009 05:15
-
-
Save tomfaulhaber/61846 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def #^{:doc "Ignore stack traces from these patterns"}ignore-files | |
[".*\\.java" "swank-clojure\\.clj" "boot\\.clj" "unit_test\\.clj"]) | |
(defn filter-stacktrace | |
"Filters a stacktrace removing file patterns defined in ignore-files." | |
[t] | |
(let [es (to-list (. t getStackTrace)) | |
top (take-while #(not (.contains (.getClassName %) "unit_test$run_test__")) es) | |
cljs (filter (comp not nil? (memfn getFileName)) top) | |
ignore-regex (str "(" (apply str (interpose "|" ignore-files)) ")") | |
ignore-pattern (re-pattern ignore-regex) | |
junk (filter (comp not | |
(partial re-matches ignore-pattern) | |
(memfn getFileName)) cljs) | |
] | |
junk)) | |
(defn assoc-append | |
"Appends an element to a map's list for a particular key." | |
[map key val] | |
(assoc map key (cons val (map key)))) | |
(defn show-stacktraces | |
"Shows a stack trace that has been filtered to hopefully show only the useful information." | |
[failures] | |
(let [f (fn [[name failure] n] | |
(println (str (inc n) ") " name ": " \newline) | |
(if (instance? java.lang.AssertionError failure) | |
(. failure getMessage) | |
(. failure toString))) | |
(doall (map (comp (partial println " ") (memfn toString)) | |
(filter-stacktrace failure))))] | |
(doall (map f failures (range (count failures)))) | |
)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment