Skip to content

Commit 4cd6dc7

Browse files
Exceptions thrown while reading now include :row and :col keys in ex-data (#181)
1 parent 4daeae4 commit 4cd6dc7

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/rewrite_clj/reader.cljc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,15 @@
1818
(defn throw-reader
1919
"Throw reader exception, including line line/column."
2020
[#?(:cljs ^:not-native reader :default reader) fmt & data]
21-
(let [c (r/get-column-number reader)
21+
(let [m (apply interop/simple-format fmt data)
22+
c (r/get-column-number reader)
2223
l (r/get-line-number reader)]
2324
(throw
2425
(ex-info
25-
(str (apply interop/simple-format fmt data)
26-
" [at line " l ", column " c "]") {}))))
26+
(str m " [at line " l ", column " c "]")
27+
{:msg m
28+
:row l
29+
:col c}))))
2730

2831
;; ## Decisions
2932

test/rewrite_clj/parser_test.cljc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,6 @@
554554
(is (= [1 1] start-pos))
555555
(is (= [3 5] end-pos))))
556556

557-
558557
(deftest t-os-specific-line-endings
559558
(are [?in ?expected]
560559
(let [str-actual (-> ?in p/parse-string-all node/string)]
@@ -585,3 +584,9 @@
585584
;1 2 3 4 5 6 7
586585
"\r\n\r\r\f\r\n\r\r\n\r"
587586
"\n\n\n\n\n\n\n"))
587+
588+
(deftest t-position-in-ex-data
589+
(let [ex (try (p/parse-string "(defn foo [)")
590+
(catch #?(:clj Exception :cljs :default) e e))]
591+
(is (= 1 (-> ex ex-data :row)))
592+
(is (= 12 (-> ex ex-data :col)))))

0 commit comments

Comments
 (0)