Live data from Hacker News

Debugging in Clojure

blog.davemartin.me

1–10 of 28 posts

Re: Debugging in Clojure

#2
The first example about spyscope potentially confuses the reader a bit by using it in context of println debugging. The point of it is you can stick it in front of any form. For a better example, see https://github.com/dgrnbrg/spyscope#spyp

Otherwise great article, I hadn't heard about scope-capture.

Re: Debugging in Clojure

#3
This isn’t mentioned in the article, but I found debug-repl [1] to be amazing when debugging in the repl. For simple prints, wrapping expressions in (doto prn) has always been enough for me without custom readers. But when debugging something super odd, just stopping somewhere and evaluating a bunch of code (with locals in scope) to understand what you’re dealing with is invaluable. Clojure’s immutability makes it especially nice since you can just rerun (most) expressions to “see what happens.”

[1] https://github.com/gfredericks/debug-repl

Re: Debugging in Clojure

#5
post #4

For those of us using CIDER don't forget #break / #dbg! https://docs.cider.mx/cider/debugging/debugger.html#using-th...

That allows you to step through code. but it doesn't break when you get a crash (like gdb). At least when I just tested:

     #dbg(defn get-first [input] (nth input 0))
     (get-first [4 2 3]) ;; 4
     (get-first 5) ;; gives me a stack trace and no program state
So it's nice to have, but I think this is maybe only useful if you're working through someone else's code?

Re: Debugging in Clojure

#6
Could `scope-capture` be used to capture state before a crash?

What would be nice is a GDB-like state along with stacktraces when you get a crash. Clojure stack traces are notoriously long and spooky. You learn to read the tea leaves, but even if you manage to identify where the crash happened and what triggered it (not always obvious..) you then need to pepper things with `println` to figure out the last local state before the whole thing blew up.

It looks like once you've found the problem area you can use `sc.api/spy` ..? It'd at least solve half the problem

Post reply on HN