Fork me on GitHub
#cider
<
2024-07-08
>
oλv09:07:45

Is there something like M-x cider-inspect for cider-stacktrace? Say my point is at saved-exception| , I would run M-x imaginary-cider-stacktrace-at-point and the exception would show up in cider-stacktrace-mode. Fwiw evalling (throw saved-exception) works fine, I just thought it’d be a neat feature 😄

vemv09:07:28

What's C-c M-i ?

oλv09:07:58

M-x cider-inspect

vemv09:07:34

On the *cider-error* buffer, if one clicks or hits RET on the exception classname, cider inspector will pop up Is that what you would want? Or do you mean in the opposite direction

oλv12:07:49

Yes, opposite direction

vemv12:07:48

Got it I created https://github.com/clojure-emacs/orchard/issues/227 earlier this year which probably be equivalent - if exceptions are rendered nicely within the Inspector and they're actionable (click to open as file), then *cider-error* wouldn't have a specific advantage, right?

oλv13:07:23

That sounds right to me

vemv13:07:59

Nice. Implementing that ticket is outside my immediate capacity It may strike @U06PNK4HG's fancy

oskarkv10:07:17

I have run into a bug with... something, I don't know what. I picked this channel because it seemed the most relevant. I have this code as part of a function

(match form
  (['try & body] :seq)
  (let [[body extra-clauses] (split-with (complement catch-clause?) body)
        body (reduce thread* value-symbol body)
        extra-clauses (mapv (fn [clause]
                              (println "clause" clause (class clause))
                              (match clause
                                (['catch kind name & body] :seq)
                                (let []
                                  (println "catch body" body)
                                  `(catch ~kind ~name
                                     (println "correct")
                                     ~@body))
                                :else
                                (do (println "finally clause")
                                    clause)))
                            extra-clauses)]
    (do
      (println extra-clauses)
      `(let [~value-symbol ~value]
         (try ~body ~@extra-clauses))))
When I make it run I get an unexpected result:
oskarkv.utils.threading> (+>$ 1 (try (/ 0) (catch Exception e inc)))
clause (catch Exception e inc) clojure.lang.PersistentList
finally clause
[(catch Exception e inc)]
#function[clojure.core/inc]
I didn't expect to see the "finally clause" there. So I tried to debug it, with cider-debug-defun-at-point. If I run through it with debug on, I get a different result:
oskarkv.utils.threading> (+>$ 1 (try (/ 0) (catch Exception e inc)))
clause (catch Exception e inc) clojure.lang.PersistentList
body (inc)
[(catch Exception e (clojure.core/println correct) inc)]
correct
#function[clojure.core/inc]
This is what I expected all along. I did not change the code; I have tried debug on and off back and forth and I get these results every time. I also get the expected result if I copy the inner function to the REPL, like:
oskarkv.utils.threading> (def abc (fn [clause]
                                    (println "clause" clause (class clause))
                                    (match clause
                                      (['catch kind name & body] :seq)
                                      (let []
                                        (println "catch body" body)
                                        `(catch ~kind ~name
                                           (println "correct")
                                           ~@body))
                                      :else
                                      (do (println "finally clause")
                                          clause))))
#'oskarkv.utils.threading/abc
oskarkv.utils.threading> (abc '(catch Exception e inc))
clause (catch Exception e inc) clojure.lang.PersistentList
catch body (inc)
(catch Exception e (clojure.core/println "correct") inc)
Does anyone have any idea of what is wrong, and what I can do about it?

vemv10:07:49

Nothing comes to mind. Perhaps I'd replace match with something that is easier to reason about

oskarkv10:07:29

Then the difference probably disappears. 😛

oyakushev10:07:02

I'm afraid you'll need a smaller reproducible example for somebody to be able to figure this out.

oskarkv10:07:51

Yeah, I'll try to make one.

vemv07:07:26

is it because of the particular body name or maybe because there's a nested match ? Either way, somewhat concerning that cider fails to keep up with that behavior

oskarkv07:07:34

If a local is bound to a name, using that name in a match clause matches only against what the local is bound to.

oskarkv07:07:47

Which is a bit surprising at first. But I guess it can be useful, if you want to let-bind a name to something complicated first, and then use that value in a match clause.

oskarkv07:07:40

I guess cider's debug mode does something to the locals which affects it.