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

Avoid overlays and messages on stderr that is unrelated to exception handling #3616

Merged
merged 3 commits into from
Feb 1, 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 @@ -6,6 +6,7 @@

- [#3605](https://github.com/clojure-emacs/cider/issues/3605): avoid `cider--error-phase-of-last-exception` recursive loop.
- [#3613](https://github.com/clojure-emacs/cider/issues/3613): adapt `cider-completion-context.el` to upstream changes in Compliment.
- [#3587](https://github.com/clojure-emacs/cider/issues/3587): avoid overlays and `message`s on stderr that is unrelated to exception handling.

## 1.13.0 (2024-01-14)

Expand Down
67 changes: 59 additions & 8 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,10 @@ It delegates the actual error content to the eval or op handler."
;; old and the new format, by utilizing a combination of two different regular
;; expressions.

(defconst cider-clojure-1.10--location `("at ("
(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))
Expand Down Expand Up @@ -612,6 +615,8 @@ It delegates the actual error content to the eval or op handler."
(optional ":" (group-n 4 (one-or-more 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-1.9-error
Expand All @@ -626,6 +631,49 @@ 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
(eval
`(rx bol (or ,cider-clojure-1.9-error
,cider-clojure-1.10-error
,cider-clojure-unexpected-error))
t)
"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
(append `(sequence
"Execution error "
(or (sequence "("
(minimal-match (one-or-more anything))
")")
(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))

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

A few example values that will match:

\"Execution error (ArithmeticException) at foo/foo (src/haystack/parser.cljc:4).\"
\"Execution error - invalid arguments to foo/bar at (src/haystack/parser.cljc:4).\"")

(defconst cider-module-info-regexp
(rx " ("
(minimal-match (one-or-more anything))
Expand Down Expand Up @@ -882,13 +930,16 @@ and the suffix matched by `cider-module-info-regexp'."
(defun cider--maybe-display-error-as-overlay (phase err end)
"Possibly display ERR as an overlay honoring END,
depending on the PHASE."
(when (or
;; if we won't show *cider-error*, because of configuration, the overlay is adequate because it compensates for the lack of info in a compact manner:
(not cider-show-error-buffer)
(not (cider-connection-has-capability-p 'jvm-compilation-errors))
;; if we won't show *cider-error*, because of an ignored phase, the overlay is adequate:
(and cider-show-error-buffer
(member phase (cider-clojure-compilation-error-phases))))
(when (and (or
;; if we won't show *cider-error*, because of configuration, the overlay is adequate because it compensates for the lack of info in a compact manner:
(not cider-show-error-buffer)
(not (cider-connection-has-capability-p 'jvm-compilation-errors))
;; if we won't show *cider-error*, because of an ignored phase, the overlay is adequate:
(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)))
;; Display errors as temporary overlays
(let ((cider-result-use-clojure-font-lock nil)
(trimmed-err (funcall cider-inline-error-message-function err)))
Expand Down
79 changes: 61 additions & 18 deletions test/cider-error-parsing-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,73 @@
(expect (col-num info) :to-equal 43)
(expect (face info) :to-equal 'cider-warning-highlight-face))))

(describe "The cider compilation regex"
(describe "The cider compilation regexes"
(it "Recognizes a clojure warning message"
(let ((clojure-compiler-warning "Reflection warning, /tmp/foo/src/foo/core.clj:14:1 - call to java.lang.Integer ctor can't be resolved."))
(expect clojure-compiler-warning :to-match cider-clojure-compilation-regexp)
(expect (progn (string-match cider-clojure-compilation-regexp clojure-compiler-warning)
(match-string 1 clojure-compiler-warning))
:to-equal "warning")))
(it "Recognizes a clojure-1.9 error message"
(let ((clojure-1.9-compiler-error "CompilerException java.lang.RuntimeException: Unable to resolve symbol: lol in this context, compiling:(/tmp/foo/src/foo/core.clj:10:1)"))
(expect clojure-1.9-compiler-error :to-match cider-clojure-compilation-regexp)
(expect (progn (string-match cider-clojure-compilation-regexp clojure-1.9-compiler-error)
(match-string 2 clojure-1.9-compiler-error))
:to-equal "/tmp/foo/src/foo/core.clj")))
(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)."))
(expect clojure-1.10-compiler-error :to-match cider-clojure-compilation-regexp)
(expect (progn (string-match cider-clojure-compilation-regexp clojure-1.10-compiler-error)
(match-string 2 clojure-1.10-compiler-error))
:to-equal "src/ardoq/service/workspace_service.clj")))
(it "Recognizes a clojure 'Unexpected error' message"
(let ((clojure-1.10-compiler-error "Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1)."))
(expect clojure-1.10-compiler-error :to-match cider-clojure-compilation-regexp)
(expect (progn (string-match cider-clojure-compilation-regexp clojure-1.10-compiler-error)
(match-string 2 clojure-1.10-compiler-error))
(dolist (regexp (list cider-clojure-compilation-regexp cider-clojure-compilation-error-regexp))
(it "Recognizes a clojure-1.9 error message"
(let ((clojure-1.9-compiler-error "CompilerException java.lang.RuntimeException: Unable to resolve symbol: lol in this context, compiling:(/tmp/foo/src/foo/core.clj:10:1)"))
(expect clojure-1.9-compiler-error :to-match regexp)
(expect (progn (string-match regexp clojure-1.9-compiler-error)
(match-string 2 clojure-1.9-compiler-error))
:to-equal "/tmp/foo/src/foo/core.clj")))
(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)."))
(expect clojure-1.10-compiler-error :to-match regexp)
(expect (progn (string-match regexp clojure-1.10-compiler-error)
(match-string 2 clojure-1.10-compiler-error))
:to-equal "src/ardoq/service/workspace_service.clj")))
(it "Recognizes a clojure 'Unexpected error' message"
(let ((clojure-1.10-compiler-error "Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1)."))
(expect clojure-1.10-compiler-error :to-match regexp)
(expect (progn (string-match regexp clojure-1.10-compiler-error)
(match-string 2 clojure-1.10-compiler-error))
:to-equal "src/haystack/parser.cljc")))))

(describe "cider-clojure-runtime-error-regexp"
(it "Recognizes a clojure-1.10 runtime error message"

;; Something like "(ArithmeticException)" will be absent for Exception and RuntimeException in particular
(let ((specimen "Execution error at foo/foo (src/haystack/parser.cljc:4)."))
(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 "src/haystack/parser.cljc"))

(let ((specimen "Execution error (ArithmeticException) at foo/foo (src/haystack/parser.cljc:4)."))
(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 "src/haystack/parser.cljc"))

;; without foo/foo symbol
(let ((specimen "Execution error at (src/haystack/parser.cljc:4)."))
(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 "src/haystack/parser.cljc"))

;; without foo/foo symbol
(let ((specimen "Execution error (ArithmeticException) at (src/haystack/parser.cljc:4)."))
(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 "src/haystack/parser.cljc")))

(it "Recognizes a clojure-1.10 runtime spec validation error message"
(let ((specimen "Execution error - invalid arguments to foo/bar at (src/haystack/parser.cljc:4)."))
(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 "src/haystack/parser.cljc"))))

(describe "cider-module-info-regexp"
Expand Down
Loading