Skip to content

Commit a650680

Browse files
committed
Introduce cider-ignored-error-phases
Fixes #3418
1 parent 9b1c9ae commit a650680

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
- `cider-test`: add timing information.
99
- `cider-test`: fail-fast by default, as controlled by the new `cider-test-fail-fast` defcustom and `cider-test-toggle-fail-fast` keybinding.
1010
- Infer indentation specs when possible ([doc](https://docs.cider.mx/cider/indent_spec.html#indentation-inference)).
11+
- [#3418](https://github.com/clojure-emacs/cider/issues/3418): Introduce `cider-ignored-error-phases`
12+
- This prevents stacktraces from showing up whenever the [:clojure.error/phase](https://clojure.org/reference/repl_and_main#_at_repl) indicates that it's a compilation error.
1113
- Add new customization variable `cider-clojurec-eval-destination` to allow specifying which REPL CLJC evals are sent to.
1214
- [#3354](https://github.com/clojure-emacs/cider/issues/3354): Add new customization variable `cider-reuse-dead-repls` to control how dead REPL buffers are reused on new connections.
1315

cider-eval.el

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ not to be automatically shown.
7070
7171
Irrespective of the value of this variable, the `cider-error-buffer' is
7272
always generated in the background. Use `cider-selector' to
73-
navigate to this buffer."
73+
navigate to this buffer.
74+
75+
Please note, if the error phase belongs to
76+
one of the `cider-ignored-error-phases', then no stacktrace showing will happen.
77+
That defcustom takes precedence over this one.
78+
79+
See its doc for understanding its rationale. You can also customize it to nil
80+
in order to void its effect."
7481
:type '(choice (const :tag "always" t)
7582
(const except-in-repl)
7683
(const only-in-repl)
@@ -478,32 +485,63 @@ op/situation that originated this error."
478485
(let ((error-buffer (cider-new-error-buffer #'cider-stacktrace-mode error-types)))
479486
(cider-stacktrace-render error-buffer (reverse causes) error-types))))
480487

481-
(defun cider--handle-stacktrace-response (response causes)
482-
"Handle stacktrace op RESPONSE, aggregating the result into CAUSES.
488+
(defcustom cider-ignored-error-phases '("read-source"
489+
"macro-syntax-check"
490+
"macroexpansion"
491+
"compile-syntax-check"
492+
"compilation"
493+
;; "execution" is certainly not to be included here.
494+
;; "read-eval-result" and "print-eval-result" are not to be included here,
495+
;; because they mean that the code has been successfully executed.
496+
)
497+
"Clojure error phases which will not trigger a UI to become visible.
498+
499+
Those UIs include, at the moment:
500+
501+
* showing stacktraces in `*cider-error*'
502+
* as otherwise controlled by the `cider-show-error-buffer' defcustom
503+
504+
`cider-ignored-error-phases' takes precedence
505+
over the other mentioned defcustoms.
506+
If you wish phases to be ignored, set this variable to nil instead.
507+
508+
You can learn more about Clojure's error phases at:
509+
https://clojure.org/reference/repl_and_main#_at_repl"
510+
:type 'list
511+
:group 'cider
512+
:package-version '(cider . "0.18.0"))
513+
514+
(defun cider--handle-stacktrace-response (response causes ex-phase)
515+
"Handle stacktrace RESPONSE, aggregate the result into CAUSES, honor EX-PHASE.
483516
If RESPONSE contains a cause, cons it onto CAUSES and return that. If
484517
RESPONSE is the final message (i.e. it contains a status), render CAUSES
485518
into a new error buffer."
486519
(nrepl-dbind-response response (class msg status type)
487520
(cond ((and (member "notification" status) causes)
488521
(nrepl-notify msg type))
489522
(class (cons response causes))
490-
(status (cider--render-stacktrace-causes causes)))))
523+
(status
524+
(unless (member ex-phase cider-ignored-error-phases)
525+
(cider--render-stacktrace-causes causes))))))
491526

492527
(defun cider-default-err-op-handler ()
493528
"Display the last exception, with middleware support."
494529
;; Causes are returned as a series of messages, which we aggregate in `causes'
495-
(let (causes)
530+
(let (causes ex-phase)
496531
(cider-nrepl-send-request
497532
(thread-last
498533
(map-merge 'list
499534
'(("op" "analyze-last-stacktrace"))
500535
(cider--nrepl-print-request-map fill-column))
501536
(seq-mapcat #'identity))
502537
(lambda (response)
538+
(nrepl-dbind-response response (phase)
539+
(when phase
540+
(setq ex-phase phase)))
503541
;; While the return value of `cider--handle-stacktrace-response' is not
504542
;; meaningful for the last message, we do not need the value of `causes'
505543
;; after it has been handled, so it's fine to set it unconditionally here
506-
(setq causes (cider--handle-stacktrace-response response causes))))))
544+
(setq causes (cider--handle-stacktrace-response response causes ex-phase))))))
507545

508546
(defun cider-default-err-handler ()
509547
"This function determines how the error buffer is shown.

0 commit comments

Comments
 (0)