Skip to content

Expand cider-clojure-compilation-regexp #3523

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

Merged
merged 2 commits into from
Oct 15, 2023
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

## master (unreleased)

### Changes

- [#3521](https://github.com/clojure-emacs/cider/issues/3521): Expand `cider-clojure-compilation-regexp` to also match e.g. `Unexpected error (ExceptionInfo) macroexpanding defmulti at (src/ns.clj:1:1).`.
- Remove module info from the [CIDER error overlay](https://docs.cider.mx/cider/usage/dealing_with_errors.html#configuration).
- Example string that is now trimmed away: `(java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IObj is in unnamed module of loader 'app')`

## 1.8.2 (2023-10-15)

### Changes
Expand Down
67 changes: 46 additions & 21 deletions cider-eval.el
Original file line number Diff line number Diff line change
Expand Up @@ -558,19 +558,31 @@ 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-error `(sequence
"Syntax error "
(minimal-match (zero-or-more anything))
(or "compiling "
"macroexpanding "
"reading source ")
(minimal-match (zero-or-more anything))
"at ("
(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--location `("at ("
(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-1.9-error `(sequence
(zero-or-more anything)
Expand All @@ -591,23 +603,34 @@ It delegates the actual error content to the eval or op handler."
(optional ":" (group-n 4 (one-or-more digit)))
" - "))


(defconst cider-clojure-compilation-regexp
(eval
`(rx bol (or ,cider-clojure-1.9-error
,cider-clojure-warning
,cider-clojure-1.10-error))
,cider-clojure-1.10-error
,cider-clojure-unexpected-error))
t)
"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).\"")

(replace-regexp-in-string cider-clojure-compilation-regexp
""
"Reflection warning, /tmp/foo/src/foo/core.clj:14:1 - call to java.lang.Integer ctor can't be resolved.")

\"Syntax error compiling at (src/workspace_service.clj:227:3).\"
\"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"")

(defconst cider-module-info-regexp
(rx " ("
(minimal-match (one-or-more anything))
" is in"
(minimal-match (one-or-more anything)) ;; module or unnamed module
" of loader "
(minimal-match (one-or-more anything))
"; "
(minimal-match (one-or-more anything))
" is in "
(minimal-match (one-or-more anything)) ;; module or unnamed module
" of loader "
(minimal-match (one-or-more anything))
")"))

(defvar cider-compilation-regexp
(list cider-clojure-compilation-regexp 2 3 4 '(1))
Expand Down Expand Up @@ -836,6 +859,8 @@ when `cider-auto-inspect-after-eval' is non-nil."
(trimmed-err (thread-last err
(replace-regexp-in-string cider-clojure-compilation-regexp
"")
(replace-regexp-in-string cider-module-info-regexp
"")
(string-trim))))
(cider--display-interactive-eval-result
trimmed-err
Expand Down
2 changes: 2 additions & 0 deletions doc/modules/ROOT/pages/usage/dealing_with_errors.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ temporary overlay or in the echo area:
(setq cider-show-error-buffer nil)
----

NOTE: you will only see the overlay if `cider-use-overlays` is non-nil.

Starting from CIDER 1.8.0, only runtime exceptions (and not compilation errors)
will cause a stacktrace buffer to be shown. This better follows Clojure 1.10's
https://clojure.org/reference/repl_and_main#_at_repl[intended semantics].
Expand Down
19 changes: 18 additions & 1 deletion test/cider-error-parsing-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,21 @@
(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"))))
: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))
:to-equal "src/haystack/parser.cljc"))))

(describe "cider-module-info-regexp"
(it "Matches module info provided by Java"
(expect " (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IObj is in unnamed module of loader 'app')"
:to-match cider-module-info-regexp)
(expect " (java.lang.Long is in module java.base of loader 'bootstrap'; clojure.lang.IObj is in module java.base of loader 'bootstrap')"
:to-match cider-module-info-regexp)
(expect " (java.lang.Long is in unnamed module of loader 'app'; clojure.lang.IObj is in module java.base of loader 'bootstrap')"
:to-match cider-module-info-regexp)
(expect " (java.lang.Long is in unnamed module of loader 'app'; clojure.lang.IObj is in unnamed module of loader 'app')"
:to-match cider-module-info-regexp)))