Skip to content

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

@JosephFerano

Description

@JosephFerano

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;

(defonce last-exception (atom nil))

Then I assign a handler to Thread/setDefaultUncaughtExceptionHandler. Something along the lines of;

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

Then on the emacs side;

(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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions