Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle negative line numbers in error messages #3688

Merged
merged 7 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 68 additions & 65 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -561,54 +561,56 @@ It delegates the actual error content to the eval or op handler."
(cider-default-err-eval-handler))
(t (cider-default-err-eval-print-handler))))


(defconst cider-clojure-1.10--location `((or "at ("
(sequence "at "
(minimal-match (one-or-more anything)) ;; the fully-qualified name of the function that triggered the error
" ("))
(group-n 2 (minimal-match (zero-or-more anything)))
":"
(group-n 3 (one-or-more digit))
(optional ":" (group-n 4 (one-or-more digit)))
")."))

(defconst cider-clojure-1.10-error (append `(sequence
"Syntax error "
(minimal-match (zero-or-more anything))
(or "compiling "
"macroexpanding "
"reading source ")
(minimal-match (zero-or-more anything)))
cider-clojure-1.10--location))

(defconst cider-clojure-unexpected-error (append `(sequence
"Unexpected error ("
(minimal-match (one-or-more anything))
") "
(or "compiling "
"macroexpanding "
"reading source ")
(minimal-match (one-or-more anything)))
cider-clojure-1.10--location))

(defconst cider-clojure-warning `(sequence
(minimal-match (zero-or-more anything))
(group-n 1 "warning")
", "
(group-n 2 (minimal-match (zero-or-more anything)))
":"
(group-n 3 (one-or-more digit))
(optional ":" (group-n 4 (one-or-more digit)))
" - "))
;; Reference:
;; https://github.com/clojure/clojure/blob/clojure-1.10.0/src/clj/clojure/main.clj#L251
;; See `cider-compilation-regexp' for interpretation of match groups.
(defconst cider-clojure-1.10--location
'(sequence
"at " (minimal-match (zero-or-more anything)) ;; the fully-qualified name of the function that triggered the error
"("
(group-n 2 (minimal-match (zero-or-more anything))) ; source file
":" (group-n 3 (one-or-more (any "-" digit))) ; line number, may be negative (#3687)
(optional
":" (group-n 4 (one-or-more (any "-" digit)))) ; column number
")."))

(defconst cider-clojure-1.10-error
`(sequence
"Syntax error "
(minimal-match (zero-or-more anything))
(or "compiling "
"macroexpanding "
"reading source ")
(minimal-match (zero-or-more anything))
,cider-clojure-1.10--location))

(defconst cider-clojure-unexpected-error
`(sequence
"Unexpected error (" (minimal-match (one-or-more anything)) ") "
(or "compiling "
"macroexpanding "
"reading source ")
(minimal-match (one-or-more anything))
,cider-clojure-1.10--location))

(defconst cider-clojure-warning
`(sequence
(minimal-match (zero-or-more anything))
(group-n 1 "warning")
", " (group-n 2 (minimal-match (zero-or-more anything)))
":" (group-n 3 (one-or-more (any "-" digit)))
(optional
":" (group-n 4 (one-or-more (any "-" digit))))
" - "))

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

(defconst cider-clojure-compilation-error-regexp
(eval
`(rx bol (or ,cider-clojure-1.10-error
,cider-clojure-unexpected-error))
t)
(rx-to-string
`(seq bol (or ,cider-clojure-1.10-error
,cider-clojure-unexpected-error))
'nogroup)
"Like `cider-clojure-compilation-regexp',
but excluding warnings such as reflection warnings.

Expand All @@ -631,26 +633,23 @@ lol in this context, compiling:(/foo/core.clj:10:1)\"
\"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"")

(defconst cider--clojure-execution-error-regexp
(append `(sequence
"Execution error "
(or (sequence "("
(minimal-match (one-or-more anything))
")")
(minimal-match (zero-or-more anything))))
cider-clojure-1.10--location))
`(sequence
"Execution error "
(minimal-match (zero-or-more anything))
,cider-clojure-1.10--location))

(defconst cider--clojure-spec-execution-error-regexp
(append `(sequence
"Execution error - invalid arguments to "
(minimal-match (one-or-more anything))
" ")
cider-clojure-1.10--location))
`(sequence
"Execution error - invalid arguments to "
(minimal-match (one-or-more anything))
" "
,cider-clojure-1.10--location))

(defconst cider-clojure-runtime-error-regexp
(eval
`(rx bol (or ,cider--clojure-execution-error-regexp
,cider--clojure-spec-execution-error-regexp))
t)
(rx-to-string
`(seq bol (or ,cider--clojure-execution-error-regexp
,cider--clojure-spec-execution-error-regexp))
'nogroup)
"Matches runtime errors, as oppsed to compile-time/macroexpansion-time errors.

A few example values that will match:
Expand All @@ -674,7 +673,11 @@ A few example values that will match:
")"))

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

Expand Down
11 changes: 10 additions & 1 deletion test/cider-error-parsing-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,16 @@
(expect (progn
(string-match cider-clojure-runtime-error-regexp specimen)
(match-string 2 specimen))
:to-equal "src/haystack/parser.cljc"))))
:to-equal "src/haystack/parser.cljc")))

;; Java source locations may be negative (#3687)
(it "Recognizes an error thrown from a java source file"
(let ((specimen "Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2)."))
(expect specimen :to-match cider-clojure-runtime-error-regexp)
(expect (progn
(string-match cider-clojure-runtime-error-regexp specimen)
(match-string 2 specimen))
:to-equal "FileInputStream.java"))))

(describe "cider-module-info-regexp"
(it "Matches module info provided by Java"
Expand Down
Loading