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

Fix another error regex bug, limit check to JVM runtime #3698

Merged
merged 6 commits into from
Jun 3, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
### Bugs fixed

- [#3696](https://github.com/clojure-emacs/cider/pull/3696): Don't eagerly complete a candidate if there are other candidates matching `flex` style.
- [#3698](https://github.com/clojure-emacs/cider/pull/3698): Fix error messages in non-JVM runtimes being suppressed when `cider-show-error-buffer` is set to `nil`.

## 1.14.0 (2024-05-30)

Expand Down
73 changes: 33 additions & 40 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ It delegates the actual error content to the eval or op handler."
;; 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
(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
"("
Expand All @@ -574,81 +574,71 @@ It delegates the actual error content to the eval or op handler."
":" (group-n 4 (one-or-more (any "-" digit)))) ; column number
")."))

(defconst cider-clojure-1.10-error
(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
(or "Syntax error reading source " ; phase = :read-source
(sequence
(or "Syntax error " "Unexpected error ")
(minimal-match (zero-or-more anything)) ; optional class, eg. (ClassCastException)
(or "macroexpanding " ; phase = :macro-syntax-check / :macroexpansion
"compiling ") ; phase = :compile-syntax-check / :compilation
(minimal-match (zero-or-more anything)))) ; optional symbol, eg. foo/bar
,cider--clojure-1.10-location)
"Regexp matching error messages triggered in compilation / read / print phases.")

(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))))
" - "))
" - ")
"Regexp matching various non-error messages, e.g. reflection warnings.")

;; Please keep this in sync with `cider-clojure-compilation-error-regexp',
;; which is a subset of these regexes.
(defconst cider-clojure-compilation-regexp
(rx-to-string
`(seq bol (or ,cider-clojure-warning
,cider-clojure-1.10-error
,cider-clojure-unexpected-error))
`(seq bol (or ,cider--clojure-warning
,cider--clojure-1.10-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: \\
lol in this context, compiling:(/foo/core.clj:10:1)\"
\"Syntax error compiling at (src/workspace_service.clj:227:3).\"
\"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"")

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

A few example values that will match:
\"CompilerException java.lang.RuntimeException: Unable to resolve symbol: \\
lol in this context, compiling:(/foo/core.clj:10:1)\"
\"Syntax error compiling at (src/workspace_service.clj:227:3).\"
\"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"")

(defconst cider--clojure-execution-error-regexp
(defconst cider--clojure-execution-error
`(sequence
"Execution error "
(minimal-match (zero-or-more anything))
,cider-clojure-1.10--location))
(or "Error reading eval result " ; phase = :read-eval-result
"Error printing return value " ; phase = :print-eval-result
"Execution error ") ; phase = :execution
(minimal-match (zero-or-more anything)) ; optional class, eg. (ArithmeticException)
,cider--clojure-1.10-location))

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

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

Expand Down Expand Up @@ -925,8 +915,11 @@ depending on the PHASE."
(and cider-show-error-buffer
(member phase (cider-clojure-compilation-error-phases))))
;; Only show overlays for things that do look like an exception (#3587):
(or (string-match-p cider-clojure-runtime-error-regexp err)
(string-match-p cider-clojure-compilation-error-regexp err)))
;; Note: only applicable to JVM Clojure error messages (#3687)
(if (cider-runtime-clojure-p)
(or (string-match-p cider-clojure-runtime-error-regexp err)
(string-match-p cider-clojure-compilation-error-regexp err))
t))
;; Display errors as temporary overlays
(let ((cider-result-use-clojure-font-lock nil)
(trimmed-err (funcall cider-inline-error-message-function err)))
Expand Down
13 changes: 11 additions & 2 deletions test/cider-error-parsing-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
(expect (progn (string-match cider-clojure-compilation-regexp clojure-compiler-warning)
(match-string 1 clojure-compiler-warning))
:to-equal "warning")))
;; FIXME: duplicate spec names
(dolist (regexp (list cider-clojure-compilation-regexp cider-clojure-compilation-error-regexp))
(it "Recognizes a clojure-1.10 error message"
(let ((clojure-1.10-compiler-error "Syntax error compiling at (src/ardoq/service/workspace_service.clj:227:3)."))
Expand Down Expand Up @@ -156,7 +157,7 @@
(match-string 2 specimen))
:to-equal "src/haystack/parser.cljc"))

;; without foo/foo symbol
;; without exception class cause-type
(let ((specimen "Execution error at (src/haystack/parser.cljc:4)."))
(expect specimen :to-match cider-clojure-runtime-error-regexp)
(expect (progn
Expand Down Expand Up @@ -187,7 +188,15 @@
(expect (progn
(string-match cider-clojure-runtime-error-regexp specimen)
(match-string 2 specimen))
:to-equal "FileInputStream.java"))))
:to-equal "FileInputStream.java")))

(it "Recognizes errors thrown during the result printing phase"
(let ((specimen "Error printing return value (ClassCastException) at clojure.core/file-seq$fn (core.clj:4997)."))
(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 "core.clj"))))

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