Skip to content

Commit 9fb72b3

Browse files
committed
Introduce cider-clojure-runtime-error-regexp
1 parent 7a83b08 commit 9fb72b3

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

cider-eval.el

+32-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,10 @@ It delegates the actual error content to the eval or op handler."
567567
;; old and the new format, by utilizing a combination of two different regular
568568
;; expressions.
569569

570-
(defconst cider-clojure-1.10--location `("at ("
570+
(defconst cider-clojure-1.10--location `((or "at ("
571+
(sequence "at "
572+
(minimal-match (one-or-more anything)) ;; the fully-qualified name of the function that triggered the error
573+
" ("))
571574
(group-n 2 (minimal-match (zero-or-more anything)))
572575
":"
573576
(group-n 3 (one-or-more digit))
@@ -626,6 +629,34 @@ lol in this context, compiling:(/foo/core.clj:10:1)\"
626629
\"Syntax error compiling at (src/workspace_service.clj:227:3).\"
627630
\"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"")
628631

632+
(defconst cider--clojure-execution-error-regexp
633+
(append `(sequence
634+
"Execution error "
635+
(or (sequence "("
636+
(minimal-match (one-or-more anything))
637+
")")
638+
(minimal-match (zero-or-more anything))))
639+
cider-clojure-1.10--location))
640+
641+
(defconst cider--clojure-spec-execution-error-regexp
642+
(append `(sequence
643+
"Execution error - invalid arguments to "
644+
(minimal-match (one-or-more anything))
645+
" ")
646+
cider-clojure-1.10--location))
647+
648+
(defconst cider-clojure-runtime-error-regexp
649+
(eval
650+
`(rx bol (or ,cider--clojure-execution-error-regexp
651+
,cider--clojure-spec-execution-error-regexp))
652+
t)
653+
"Matches runtime errors, as oppsed to compile-time/macroexpansion-time errors.
654+
655+
A few example values that will match:
656+
657+
\"Execution error (ArithmeticException) at foo/foo (src/haystack/parser.cljc:4).\"
658+
\"Execution error - invalid arguments to foo/bar at (src/haystack/parser.cljc:4).\"")
659+
629660
(defconst cider-module-info-regexp
630661
(rx " ("
631662
(minimal-match (one-or-more anything))

test/cider-error-parsing-tests.el

+42
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,48 @@
143143
(match-string 2 clojure-1.10-compiler-error))
144144
:to-equal "src/haystack/parser.cljc"))))
145145

146+
(describe "cider-clojure-runtime-error-regexp"
147+
(it "Recognizes a clojure-1.10 runtime error message"
148+
149+
;; Something like "(ArithmeticException)" will be absent for Exception and RuntimeException in particular
150+
(let ((specimen "Execution error at foo/foo (src/haystack/parser.cljc:4)."))
151+
(expect specimen :to-match cider-clojure-runtime-error-regexp)
152+
(expect (progn
153+
(string-match cider-clojure-runtime-error-regexp specimen)
154+
(match-string 2 specimen))
155+
:to-equal "src/haystack/parser.cljc"))
156+
157+
(let ((specimen "Execution error (ArithmeticException) at foo/foo (src/haystack/parser.cljc:4)."))
158+
(expect specimen :to-match cider-clojure-runtime-error-regexp)
159+
(expect (progn
160+
(string-match cider-clojure-runtime-error-regexp specimen)
161+
(match-string 2 specimen))
162+
:to-equal "src/haystack/parser.cljc"))
163+
164+
;; without foo/foo symbol
165+
(let ((specimen "Execution error at (src/haystack/parser.cljc:4)."))
166+
(expect specimen :to-match cider-clojure-runtime-error-regexp)
167+
(expect (progn
168+
(string-match cider-clojure-runtime-error-regexp specimen)
169+
(match-string 2 specimen))
170+
:to-equal "src/haystack/parser.cljc"))
171+
172+
;; without foo/foo symbol
173+
(let ((specimen "Execution error (ArithmeticException) at (src/haystack/parser.cljc:4)."))
174+
(expect specimen :to-match cider-clojure-runtime-error-regexp)
175+
(expect (progn
176+
(string-match cider-clojure-runtime-error-regexp specimen)
177+
(match-string 2 specimen))
178+
:to-equal "src/haystack/parser.cljc")))
179+
180+
(it "Recognizes a clojure-1.10 runtime spec validation error message"
181+
(let ((specimen "Execution error - invalid arguments to foo/bar at (src/haystack/parser.cljc:4)."))
182+
(expect specimen :to-match cider-clojure-runtime-error-regexp)
183+
(expect (progn
184+
(string-match cider-clojure-runtime-error-regexp specimen)
185+
(match-string 2 specimen))
186+
:to-equal "src/haystack/parser.cljc"))))
187+
146188
(describe "cider-module-info-regexp"
147189
(it "Matches module info provided by Java"
148190
(expect " (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IObj is in unnamed module of loader 'app')"

0 commit comments

Comments
 (0)