clojure-emacs / clojure-emacs/cider

Mechanism to catch and open exceptions from other threads in *cider-error* popup

Open
#3,850 5 comments 1 reaction 0 assignees View on GitHub
stale
Dominant language
Emacs Lisp
Stars
3.7k
Forks
651
Avg merge
11h 6m
Merged PRs (30d)
33

Description

**Is your feature request related to a problem? Please describe.**

The cider error buffer is a great way to make Clojure's exceptions more ergonomic to read. However, if they are thrown from a different thread, such as when fiddling with UI in a JavaFx thread, then Cider is unable to catch them such that they raise the popup error buffer.

**Describe the solution you'd like**

Some sort of mechanism by which I can hook exceptions in other threads to trigger the cider error buffer popup.

**Describe alternatives you've considered**

Currently, I got it working, here's what i did;

First I used a workaround suggested in the slack;

```clojure
(defonce last-exception (atom nil))
```
Then I assign a handler to `Thread/setDefaultUncaughtExceptionHandler`. Something along the lines of;

```clojure
(when (System/getProperty "cider-dev")
(reset! last-exception exception)
(log/error :message "EMACS-CIDER-REPORT-EXCEPTION"))
```

Then on the emacs side;

```elisp
(defun joe/clojure-cider-throw-last-error ()
(interactive)
(cider-interactive-eval "\(throw @last-exception\)"))

(defun joe/cider-repl-preoutput-hook (output)
(if (string-match "EMACS-CIDER-REPORT-EXCEPTION" output)
(progn
(joe/clojure-cider-throw-last-error)
"")
output))

(add-hook 'cider-repl-preoutput-hook #'joe/cider-repl-preoutput-hook)
```

The key being `cider-repl-preoutput-hook`

Contributor guide

Open the contributing guide

Research direction

Start by tracing how exceptions reach the *cider-error* popup and compare that path with the reported Thread/setDefaultUncaughtExceptionHandler workaround. Read the cider-repl-preoutput-hook example and determine how a supported cross-thread hook could trigger the popup. Done should include a documented mechanism that catches exceptions from other threads and opens the cider error buffer.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure, emacs-lisp
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.