Hi, thank you for Cider, It's really amazing. I wanted to ask a question about the cider-error buffer. It's really good and it pops up as expected. However, I'm developing with a JavaFx/cljfx application and when exceptions occur in the thread "JavaFX Application Thread" because I did something wrong from the UI view, the exception only gets shown in the cider repl. I can still jump to lines in the stracktrace by clicking on them, but it would be nice to get the cider-error buffer since it's more featureful. Is this possible?
Ok, so I got it to automatically throw exceptions for me. Using this function
Thread/setDefaultUncaughtExceptionHandler
I then have this snippet in the function handler
(defonce last-exception (atom nil))
... Further down
(if (System/getProperty "cider-dev")
(do
(reset! last-exception exception)
(log/error :message "EMACS-CIDER-REPORT-EXCEPTION")
That message is important
On the emacs side I found the hook cider-repl-preoutput-hook;
(defun joe/clojure-cider-throw-last-error ()
(interactive)
(cider-interactive-eval "\(throw @editor.error-reporting/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)
And it works. Exceptions from JavaFx threads (and probably any thread) now trigger the cider-error bufferCreated the issue describing what I did
I need to debounce it 🙂
As a hack, I can suggest wrapping your UI code in (try ... (catch Exception ex (def -my-error ex) (throw ex)), and then if you want to view the exception with cider-error buffer, manually call (throw -my-error).
Not a bad hack 😁
We used to have a way to convert stderr stacktrace output into viewable/clickable cider-error buffer, but it wasn't very reliable and added a lot of complexity
But overall, it would be an interesting idea to be able to "send" an error to cider-error. I would appreaciate if you created a feature request, we may actually do it someday
Sure thing
Thanks for the reply
I see potential for another awesome cider-inspector view... :)
[Offtopic: stumbling upon the new byte-buffer view made my day when I was fiddling with UDP. Thanks for the great work!]
CIDER inspector already has a special view for Throwable objects, but it is still not as optimized as cider-error buffer. It is still more about navigating data. For example, it can't jump to source definition which is not really inspector's job.
I faced this exact same issue recently with ring handlers running in a separate thread, and came up with essentially the same hack:
(defonce last-error_ (atom nil))
(defn wrap-error [handler on-error]
(fn [req]
(try (handler req)
(catch Throwable t
(reset! last-error_ t)
(on-error req t)
{:status 500
:body (pr-str (ex-message t))}))))
and while debugging I'd just have (throw @app.handlers/last_error_) in a nearby comment form and eval it when neededOh! The Throwable view is so seemless that I didn't even notice 🙂
Jump to source on a stacktrace-as-data line looks like a good candidate for a (buffer agnostic) embark target/action, provided by the user, not cider.