Skip to content

Commit

Permalink
Expand cider-clojure-compilation-regexp
Browse files Browse the repository at this point in the history
Fixes #3521
  • Loading branch information
vemv committed Oct 15, 2023
1 parent 93da20e commit 599a67c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 22 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## 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).`.

## 1.8.2 (2023-10-15)

### Changes
Expand Down
50 changes: 29 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,19 @@ 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).\"")

(defvar cider-compilation-regexp
(list cider-clojure-compilation-regexp 2 3 4 '(1))
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
8 changes: 7 additions & 1 deletion test/cider-error-parsing-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,10 @@
(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"))))

0 comments on commit 599a67c

Please sign in to comment.