The absolutely most useful thing I reach for time and again is the dbg
macro:
http://www.learningclojure.com/2010/09/clojure-macro-tutorial-part-i-getting.html
(defmacro dbg[x] `(let [x# ~x] (println '~x "=" x#) x#))
My current variation:
(defn pprint-str
[x]
(with-out-str (pp/pprint x)))
(defmacro dbg
[x]
`(let [x# ~x]
(printf "dbg %s:%s> %s is %s\n"
~*ns*
~(:line (meta &form))
~(pr-str x)
(pprint-str x#))
(flush)
x#))
On Wed, Nov 6, 2013 at 10:37 PM, Jeffrey Charles
wrote:
> I'm interested in hearing how people who use Clojure in production are
> debugging their code, particularly those who use Emacs.
>
> I am having issues quickly locating problems in my Clojure code that are
> identified by automated integration test failures. As an example, I had a
> Midje test that would make an HTTP call into my application running
> Compojure and Liberator on Ring on Jetty and I'd get an error back in a
> stacktrace in my shell running the Ring process. I got to a somewhat useful
> error of not being able to find a terminator for a JSON object which I
> correctly divined was actually that the request body was empty. My usual
> approach to debugging these sorts of problems in C# and Visual Studio is to
> set the built-in debugger to break on CLR exceptions and then run the
> integration test with my debugger attached to the web server process and
> take a look at the exception and local variables starting at the bottom of
> the stack and going up the stack until I spot something funky. I'm
> completely lost in figuring out how to do something similar in Clojure and
> Emacs or a shell, that is to say, running something that will pause
> execution and let me examine the exception and in-scope variables on a
> stack frame by stack frame basis with source code context (bonus points if
> it's a REPL).
>
> One thing I've taken a look at is ritz and ritz-nrepl but I seem to get
> errors when I try to use them. Specifically, "Symbol's value as variable is
> void: nrepl-mode-map" which seems to be an already reported issue. As well,
> the Github repositories don't appear to have been updated in several months
> which makes me pessimistic that these libraries will be meaningfully
> maintained and as a result, I feel uncomfortable relying on them.
>
> Another thing I looked at was George Jahad's Clojure Debug Toolkit which
> also doesn't seem to have gotten any love in the last few years and has
> pretty minimal public documentation around using it..
>
> While playing around with functions in the REPL usually does the job,
> sometimes the bugs and their locations are not obvious or they're at
> integration points where the input is a complicated object. I'd like to
> know what other developers who use Clojure do when they need to debug
> something and a REPL in a namespace with minimal execution context doesn't
> seem to do the trick.
>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
--
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
---
You received this message because you are subscribed to the Google Groups
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.