Midje icon indicating copy to clipboard operation
Midje copied to clipboard

Point users to (pst *e) to help troubleshoot autotest in repl failures

Open holyjak opened this issue 10 years ago • 3 comments

The single-line error printed in the REPL when running Midje that fails due to an exception should mention that the user may get the full stack trace via (clojure.repl/pst *e) - this is not obvious to devs fairly experienced with Clojure. (Or may be there is another, yet better way?) To be concrete, when I evaled my file in REPL (which triggers Midje thanks to the check on load seting), I got this unhelful failure:

Loading test/reward.clj... done

WORK TO DO "About rewards" at (reward.clj:130)
CompilerException java.lang.NullPointerException, compiling:(/example//test/reward.clj:491:14) 

The location is useless - it points to the setup method I call from my fact but not to the actual place that triggers the NPE:

; ...
(defn setup
  [test-users]
  (drop-test-data-below-neg100k)
  (insert-test-data test-users)
  (reward/compute rewards)
  test-users) ;; <----- place 491:14 is here, after the )

I am lucky enough to know to do this to find out the actual source of the NPE:

reward> (clojure.repl/pst *e)
CompilerException java.lang.NullPointerException, compiling:(/example/test/reward.clj:491:14)
    clojure.lang.Compiler.load (Compiler.java:7142)
    ...
    clojure.core/with-bindings* (core.clj:1862)
Caused by:
NullPointerException 
    clojure.lang.Numbers.ops (Numbers.java:961)
    clojure.lang.Numbers.minus (Numbers.java:135)
    reward/mk-user (reward.clj:402) <----- the NPE is triggered here
    reward/mk-users (reward.clj:429)
    clojure.core/apply (core.clj:624)
    reward/mk-users (reward.clj:427)
    reward/eval30273/fn--30274/fn--30275 (reward.clj:493)
    midje.util.thread-safe-var-nesting/with-altered-roots* (thread_safe_var_nesting.clj:32)
    reward/eval30273/fn--30274 (reward.clj:493)
    clojure.lang.AFunction$1.doInvoke (AFunction.java:29)
    midje.checking.facts/check-one/fn--29733 (facts.clj:31)
    midje.checking.facts/check-one (facts.clj:30)

(For the curious: the problem was that I did (- num another-num) when one of those were null.)


An error like the following one would be much more useful for less experienced devs:

CompilerException java.lang.NullPointerException, compiling:(/example/test/reward.clj:491:14) *[Run (clojure.repl/pst e) to print the stack trace]

Thank you!

holyjak avatar Jul 01 '14 12:07 holyjak

I agree. I'll want to think a bit about when such a message might be misleading.

marick avatar Jul 04 '14 22:07 marick

+1

bilus avatar Aug 19 '14 20:08 bilus

Trello card https://trello.com/c/8sk9yCK1/8-point-users-to-pst-e-to-help-troubleshoot-autotest-in-repl-failures-285

marick avatar Nov 28 '14 21:11 marick