Skip to content

Commit

Permalink
Merge pull request #27 from nahuel/fix-short-stacktraces-bug
Browse files Browse the repository at this point in the history
fixes IndexOutOfBoundsExceptions when trying to print exceptions
  • Loading branch information
technomancy committed Oct 14, 2013
2 parents 99b859f + 62d3d19 commit 344fa2c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/clj_stacktrace/repl.clj
Expand Up @@ -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))
Expand Down Expand Up @@ -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))))))]
Expand Down Expand Up @@ -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)))
Expand Down

0 comments on commit 344fa2c

Please sign in to comment.