Live data from Hacker News

Debugging in Clojure

blog.davemartin.me

11–20 of 28 posts

Re: Debugging in Clojure

#11

Elephant in the room: Sayid. It's made for Emacs, and it's so powerful, you may want to switch to Emacs just because of it.

Sayid does look really powerful. However, I declared Emacs bankruptcy years ago, and switched to Cursive. If I ever have the courage to switch back, I'll give Sayid a go :P

Re: Debugging in Clojure

#13
post #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…

Assuming the crash doesn't cause the process to completely exit, you could indeed use `scope-capture` for this. This works well for local dev. In theory, you could use `sc.api/spy` in production code, and then attach a remote repl to diagnose any crashes. I wouldn't recommend this though, I think it would be best to use a good logging library like Mulog: https://github.com/BrunoBonacci/mulog

Re: Debugging in Clojure

#14

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 es…

I've heard good things about debug-repl, although I haven't used it myself. From what I understand, it fills a similar niche to scope-capture. However you do it, being able to capture the state at a certain point in the code is essential.

Re: Debugging in Clojure

#15
post #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.

Thanks! Perhaps the wording isn't great in that paragraph, I intended the phrase "println debugging" to mean the general style of debugging, rather than specifically using the println function.

Re: Debugging in Clojure

#16

Does the Clojure debugger give a live Repl, where one can examine values of locals and restart execution if required, likes the elisp debugger in Emacs?

Cursive's debugger doesn't, but as one of the other posters mentioned there's a library called debug-repl which gives you this: https://github.com/gfredericks/debug-repl.

However, as I mentioned in the article, I've found it's usually better to use scope-capture than a debugger that pauses execution. The main reason is that I mainly work with Kafka Streams atm, and when the debugger pauses one thread other threads start timing out and throwing exceptions.

Re: Debugging in Clojure

#18
post #16

Does the Clojure debugger give a live Repl, where one can examine values of locals and restart execution if required, likes the elisp debugger in Emacs?

Cursive's debugger doesn't, but as one of the other posters mentioned there's a library called debug-repl which gives you this: https://github.com/gfredericks/debug-repl . However, as I mentioned in the article, I've found it's usually better to use scope-capture than a debugger that pauses execution. The main reason is that I mainly work with Kafka Streams atm, and when the debugger pauses one thread other threads s…

That seems to give a repl at a breakpoint, I was asking about getting a repl at a point of exception. That is what elisp gives.

Re: Debugging in Clojure

#19
post #16

Earlier quoted context omitted.

Cursive's debugger doesn't, but as one of the other posters mentioned there's a library called debug-repl which gives you this: https://github.com/gfredericks/debug-repl . However, as I mentioned in the article, I've found it's usually better to use scope-capture than a debugger that pauses execution. The main reason is that I mainly work with Kafka Streams atm, and when the debugger pauses one thread other threads s…

That seems to give a repl at a breakpoint, I was asking about getting a repl at a point of exception. That is what elisp gives.

Ah sorry, I don't know of a way of doing that in Clojure. What I usually do is figure out where the exception was thrown, wrap that form in `sc.api/spy`, and then somehow re-execute it.

Re: Debugging in Clojure

#20
post #16

Does the Clojure debugger give a live Repl, where one can examine values of locals and restart execution if required, likes the elisp debugger in Emacs?

Cursive's debugger doesn't, but as one of the other posters mentioned there's a library called debug-repl which gives you this: https://github.com/gfredericks/debug-repl . However, as I mentioned in the article, I've found it's usually better to use scope-capture than a debugger that pauses execution. The main reason is that I mainly work with Kafka Streams atm, and when the debugger pauses one thread other threads s…

Cursive's debugger does let you restart the execution?

It's a normal step debugger, and you can run new expressions in context are we talking about lisp restarts?

Post reply on HN