Improved stack traces

147 views
Skip to first unread message

Rich Hickey

unread,
Sep 9, 2010, 4:58:42 PM9/9/10
to Clojure
People frequently complain about Clojure's stack traces, and there are
now some enhancements in the master branch. In particular, there is a
new function in clojure.repl, pst, which prints a nicer stack trace of
the most recent (or a supplied) exception. It also has depth control.
pst is automatically available in the standard REPL.

The single-line initial messages should also be better.

Note as always that if you have a compilation/syntax error, the stack
can of course have nothing on it but the compiler logic itself. But
the file and line number of the code being compiled will, if
available, be in the single-line report.

Feedback welcome,

Rich

Alan

unread,
Sep 9, 2010, 5:12:30 PM9/9/10
to Clojure
I assume I'm just clueless here, but the last commit I see at
http://github.com/richhickey/clojure is one from Stuart Halloway in
June. Where do I find this so I can try it out? Or, what version do I
have to tell leiningen I depend on - 1.2.0-snapshot, 1.3.0-snapshot,
or something like that?

Nicolas Oury

unread,
Sep 9, 2010, 5:19:34 PM9/9/10
to clo...@googlegroups.com

Mike Hinchey

unread,
Sep 10, 2010, 9:19:03 PM9/10/10
to clo...@googlegroups.com
I found when working on ticket 191 (dead now, I suppose) that counting the stack elements is not reliable, but = works to get rid of duplicates.  Below you can compare java's to your new function - the clojure has one duplicate element (the very last one).  Also, I find the "..." useful to know something is cut off.

root-cause is too generic of a name since it only strips out CompileException.

Will clojure.stacktrace be deprecated or patched to use this implementation?

My patch for 191 includes test code if you want to adjust it for this.

-Mike

user=> (.printStackTrace *e)
java.lang.Exception: Unable to resolve symbol: x in this context, compiling:(NO_SOURCE_FILE:0)
        at clojure.lang.Compiler.analyze(Compiler.java:5777)
        at clojure.lang.Compiler.analyze(Compiler.java:5723)
        at clojure.lang.Compiler.eval(Compiler.java:6002)
        at clojure.lang.Compiler.eval(Compiler.java:5965)
        at clojure.core$eval.invokeStatic(core.clj:2652)
        at clojure.core$eval.invoke(core.clj)
        at clojure.main$repl$read_eval_print__5766.invoke(main.clj:177)
        at clojure.main$repl$fn__5771.invoke(main.clj:198)
        at clojure.main$repl.doInvoke(main.clj:198)
        at clojure.lang.RestFn.invoke(RestFn.java:422)
        at clojure.main$repl_opt.invoke(main.clj:256)
        at clojure.main$main.doInvoke(main.clj:349)
        at clojure.lang.RestFn.invoke(RestFn.java:398)
        at clojure.lang.Var.invoke(Var.java:361)
        at clojure.lang.AFn.applyToHelper(AFn.java:159)
        at clojure.lang.Var.applyTo(Var.java:482)
        at clojure.main.main(main.java:37)
Caused by: java.lang.Exception: Unable to resolve symbol: x in this context
        at clojure.lang.Compiler.resolveIn(Compiler.java:6251)
        at clojure.lang.Compiler.resolve(Compiler.java:6195)
        at clojure.lang.Compiler.analyzeSymbol(Compiler.java:6158)
        at clojure.lang.Compiler.analyze(Compiler.java:5744)
        ... 16 more
nil

user=> (pst *e 40)
CompilerException java.lang.Exception: Unable to resolve symbol: x in this context, compiling:(NO_SOURCE_FILE:0)
        clojure.lang.Compiler.analyze (Compiler.java:5777)
        clojure.lang.Compiler.analyze (Compiler.java:5723)
        clojure.lang.Compiler.eval (Compiler.java:6002)
        clojure.lang.Compiler.eval (Compiler.java:5965)
        clojure.core/eval (core.clj:2652)
        clojure.core/eval (core.clj:-1)
        clojure.main/repl/read-eval-print--5766 (main.clj:177)
        clojure.main/repl/fn--5771 (main.clj:198)
        clojure.main/repl (main.clj:198)
        clojure.main/repl-opt (main.clj:256)
        clojure.main/main (main.clj:349)
        clojure.lang.Var.invoke (Var.java:361)
        clojure.lang.Var.applyTo (Var.java:482)
        clojure.main.main (main.java:37)
Caused by:
Exception Unable to resolve symbol: x in this context
        clojure.lang.Compiler.resolveIn (Compiler.java:6251)
        clojure.lang.Compiler.resolve (Compiler.java:6195)
        clojure.lang.Compiler.analyzeSymbol (Compiler.java:6158)
        clojure.lang.Compiler.analyze (Compiler.java:5744)
        clojure.lang.Compiler.analyze (Compiler.java:5723)
nil

Reply all
Reply to author
Forward
0 new messages