Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixes IndexOutOfBoundsExceptions when trying to print exceptions with…

… short stack traces (< 3 StackElements). Fixes mmcgrana/clj-stacktrace#25 and mmcgrana/clj-stacktrace#26
  • Loading branch information...
commit 62d3d1998b6188e0dc89e5e411695feda25307ef 1 parent 99b859f
@nahuel nahuel authored
Showing with 10 additions and 2 deletions.
  1. +10 −2 src/clj_stacktrace/repl.clj
View
12 src/clj_stacktrace/repl.clj
@@ -33,6 +33,14 @@
(re-find #"^clojure\." (:ns elem)) :magenta
:user-code :green)))
+(defn- guarded-fence [coll]
+ (case (count coll)
+ 0 0
+ 1 (first coll)
+ 2 (quot (+ (first coll)
+ (second coll)) 2)
+ (utils/fence coll)))
+
(defn source-str [parsed]
(if (and (:file parsed) (:line parsed))
(str (:file parsed) ":" (:line parsed))
@@ -65,7 +73,7 @@
(defn pst-elems-on
[^java.io.Writer on color? parsed-elems & [source-width]]
(let [print-width (+ 6 (or source-width
- (utils/fence
+ (guarded-fence
(sort
(map #(.length ^String %)
(map source-str parsed-elems))))))]
@@ -95,7 +103,7 @@
(let [this-source-width (->> (:trace-elems excp)
(map (comp count source-str))
(sort)
- (utils/fence))]
+ (guarded-fence))]
(if (not-empty (-> excp :cause :trace-elems))
(max this-source-width (find-source-width (:cause excp)))
this-source-width)))
Please sign in to comment.
Something went wrong with that request. Please try again.