Skip to content

Commit 8d67a14

Browse files
authored
Merge pull request #3688 from yuhan0/fix-error-regex
Handle negative line numbers in error messages
2 parents a74dff9 + 348dc15 commit 8d67a14

File tree

2 files changed

+78
-66
lines changed

2 files changed

+78
-66
lines changed

cider-eval.el

Lines changed: 68 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -561,54 +561,56 @@ It delegates the actual error content to the eval or op handler."
561561
(cider-default-err-eval-handler))
562562
(t (cider-default-err-eval-print-handler))))
563563

564-
565-
(defconst cider-clojure-1.10--location `((or "at ("
566-
(sequence "at "
567-
(minimal-match (one-or-more anything)) ;; the fully-qualified name of the function that triggered the error
568-
" ("))
569-
(group-n 2 (minimal-match (zero-or-more anything)))
570-
":"
571-
(group-n 3 (one-or-more digit))
572-
(optional ":" (group-n 4 (one-or-more digit)))
573-
")."))
574-
575-
(defconst cider-clojure-1.10-error (append `(sequence
576-
"Syntax error "
577-
(minimal-match (zero-or-more anything))
578-
(or "compiling "
579-
"macroexpanding "
580-
"reading source ")
581-
(minimal-match (zero-or-more anything)))
582-
cider-clojure-1.10--location))
583-
584-
(defconst cider-clojure-unexpected-error (append `(sequence
585-
"Unexpected error ("
586-
(minimal-match (one-or-more anything))
587-
") "
588-
(or "compiling "
589-
"macroexpanding "
590-
"reading source ")
591-
(minimal-match (one-or-more anything)))
592-
cider-clojure-1.10--location))
593-
594-
(defconst cider-clojure-warning `(sequence
595-
(minimal-match (zero-or-more anything))
596-
(group-n 1 "warning")
597-
", "
598-
(group-n 2 (minimal-match (zero-or-more anything)))
599-
":"
600-
(group-n 3 (one-or-more digit))
601-
(optional ":" (group-n 4 (one-or-more digit)))
602-
" - "))
564+
;; Reference:
565+
;; https://github.com/clojure/clojure/blob/clojure-1.10.0/src/clj/clojure/main.clj#L251
566+
;; See `cider-compilation-regexp' for interpretation of match groups.
567+
(defconst cider-clojure-1.10--location
568+
'(sequence
569+
"at " (minimal-match (zero-or-more anything)) ;; the fully-qualified name of the function that triggered the error
570+
"("
571+
(group-n 2 (minimal-match (zero-or-more anything))) ; source file
572+
":" (group-n 3 (one-or-more (any "-" digit))) ; line number, may be negative (#3687)
573+
(optional
574+
":" (group-n 4 (one-or-more (any "-" digit)))) ; column number
575+
")."))
576+
577+
(defconst cider-clojure-1.10-error
578+
`(sequence
579+
"Syntax error "
580+
(minimal-match (zero-or-more anything))
581+
(or "compiling "
582+
"macroexpanding "
583+
"reading source ")
584+
(minimal-match (zero-or-more anything))
585+
,cider-clojure-1.10--location))
586+
587+
(defconst cider-clojure-unexpected-error
588+
`(sequence
589+
"Unexpected error (" (minimal-match (one-or-more anything)) ") "
590+
(or "compiling "
591+
"macroexpanding "
592+
"reading source ")
593+
(minimal-match (one-or-more anything))
594+
,cider-clojure-1.10--location))
595+
596+
(defconst cider-clojure-warning
597+
`(sequence
598+
(minimal-match (zero-or-more anything))
599+
(group-n 1 "warning")
600+
", " (group-n 2 (minimal-match (zero-or-more anything)))
601+
":" (group-n 3 (one-or-more (any "-" digit)))
602+
(optional
603+
":" (group-n 4 (one-or-more (any "-" digit))))
604+
" - "))
603605

604606
;; Please keep this in sync with `cider-clojure-compilation-error-regexp',
605607
;; which is a subset of these regexes.
606608
(defconst cider-clojure-compilation-regexp
607-
(eval
608-
`(rx bol (or ,cider-clojure-warning
609-
,cider-clojure-1.10-error
610-
,cider-clojure-unexpected-error))
611-
t)
609+
(rx-to-string
610+
`(seq bol (or ,cider-clojure-warning
611+
,cider-clojure-1.10-error
612+
,cider-clojure-unexpected-error))
613+
'nogroup)
612614
"A few example values that will match:
613615
\"Reflection warning, /tmp/foo/src/foo/core.clj:14:1 - \"
614616
\"CompilerException java.lang.RuntimeException: Unable to resolve symbol: \\
@@ -617,10 +619,10 @@ lol in this context, compiling:(/foo/core.clj:10:1)\"
617619
\"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"")
618620

619621
(defconst cider-clojure-compilation-error-regexp
620-
(eval
621-
`(rx bol (or ,cider-clojure-1.10-error
622-
,cider-clojure-unexpected-error))
623-
t)
622+
(rx-to-string
623+
`(seq bol (or ,cider-clojure-1.10-error
624+
,cider-clojure-unexpected-error))
625+
'nogroup)
624626
"Like `cider-clojure-compilation-regexp',
625627
but excluding warnings such as reflection warnings.
626628
@@ -631,26 +633,23 @@ lol in this context, compiling:(/foo/core.clj:10:1)\"
631633
\"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"")
632634

633635
(defconst cider--clojure-execution-error-regexp
634-
(append `(sequence
635-
"Execution error "
636-
(or (sequence "("
637-
(minimal-match (one-or-more anything))
638-
")")
639-
(minimal-match (zero-or-more anything))))
640-
cider-clojure-1.10--location))
636+
`(sequence
637+
"Execution error "
638+
(minimal-match (zero-or-more anything))
639+
,cider-clojure-1.10--location))
641640

642641
(defconst cider--clojure-spec-execution-error-regexp
643-
(append `(sequence
644-
"Execution error - invalid arguments to "
645-
(minimal-match (one-or-more anything))
646-
" ")
647-
cider-clojure-1.10--location))
642+
`(sequence
643+
"Execution error - invalid arguments to "
644+
(minimal-match (one-or-more anything))
645+
" "
646+
,cider-clojure-1.10--location))
648647

649648
(defconst cider-clojure-runtime-error-regexp
650-
(eval
651-
`(rx bol (or ,cider--clojure-execution-error-regexp
652-
,cider--clojure-spec-execution-error-regexp))
653-
t)
649+
(rx-to-string
650+
`(seq bol (or ,cider--clojure-execution-error-regexp
651+
,cider--clojure-spec-execution-error-regexp))
652+
'nogroup)
654653
"Matches runtime errors, as oppsed to compile-time/macroexpansion-time errors.
655654
656655
A few example values that will match:
@@ -674,7 +673,11 @@ A few example values that will match:
674673
")"))
675674

676675
(defvar cider-compilation-regexp
677-
(list cider-clojure-compilation-regexp 2 3 4 '(1))
676+
(list cider-clojure-compilation-regexp
677+
2 ; FILE
678+
3 ; LINE
679+
4 ; COLUMN
680+
'(1)) ; TYPE = (WARNING . INFO)
678681
"Specifications for matching errors and warnings in Clojure stacktraces.
679682
See `compilation-error-regexp-alist' for help on their format.")
680683

test/cider-error-parsing-tests.el

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,16 @@
178178
(expect (progn
179179
(string-match cider-clojure-runtime-error-regexp specimen)
180180
(match-string 2 specimen))
181-
:to-equal "src/haystack/parser.cljc"))))
181+
:to-equal "src/haystack/parser.cljc")))
182+
183+
;; Java source locations may be negative (#3687)
184+
(it "Recognizes an error thrown from a java source file"
185+
(let ((specimen "Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2)."))
186+
(expect specimen :to-match cider-clojure-runtime-error-regexp)
187+
(expect (progn
188+
(string-match cider-clojure-runtime-error-regexp specimen)
189+
(match-string 2 specimen))
190+
:to-equal "FileInputStream.java"))))
182191

183192
(describe "cider-module-info-regexp"
184193
(it "Matches module info provided by Java"

0 commit comments

Comments
 (0)