Skip to content

Commit 5781984

Browse files
danielcomptondnolen
authored andcommitted
CLJS-1907: Improve error message from cljs.reader/read-string
When reading keywords with numbers first. Before this patch, re-matches* would return nil, and then the aget for token would throw an error that null is not an object.
1 parent 92de138 commit 5781984

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/main/cljs/cljs/reader.cljs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ nil if the end of stream has been reached")
365365
[reader initch]
366366
(let [token (read-token reader (read-char reader))
367367
a (re-matches* symbol-pattern token)
368+
_ (when (nil? a) (reader-error reader "Invalid keyword " (str ":" token)))
368369
token (aget a 0)
369370
ns (aget a 1)
370371
name (aget a 2)]

src/test/cljs/cljs/reader_test.cljs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,3 +223,7 @@
223223
(is (= "Duplicate key: :a" b))
224224
(is (= "Duplicate key: :a" c))
225225
(is (= "Duplicate key: :a" d))))
226+
227+
(deftest test-error-messages
228+
(testing "Leading numbers in keywords"
229+
(is (thrown-with-msg? js/Error #"Invalid keyword :0s" (reader/read-string ":0s")))))

0 commit comments

Comments
 (0)