Clojure

clojure.test does not print ex-info in error reports

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Critical Critical
  • Resolution: Unresolved
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Patch:
    Code
  • Approval:
    Triaged

Description

clojure.test does not print the data attached to ExceptionInfo in error reports.

(use 'clojure.test)
(deftest ex-test (throw (ex-info "err" {:some :data})))
(ex-test)

ERROR in (ex-test) (core.clj:4591)
Uncaught exception, not in assertion.
expected: nil
  actual: clojure.lang.ExceptionInfo: err
 at clojure.core$ex_info.invoke (core.clj:4591)
    user/fn (NO_SOURCE_FILE:2)
    clojure.test$test_var$fn__7666.invoke (test.clj:704)
    clojure.test$test_var.invoke (test.clj:704)
    ...

Approach: In clojure.stacktrace, which clojure.test uses for printing exceptions, add a check for ex-data and pr it.

After:

ERROR in (ex-test) (core.clj:4591)
Uncaught exception, not in assertion.
expected: nil
  actual: clojure.lang.ExceptionInfo: err
{:some :data}
 at clojure.core$ex_info.invoke (core.clj:4591)
    user/fn (NO_SOURCE_FILE:3)
    clojure.test$test_var$fn__7667.invoke (test.clj:704)
    clojure.test$test_var.invoke (test.clj:704)

Patch: 0002-CLJ-1209-show-ex-data-in-clojure-test.patch

Activity

Hide
Alex Miller added a comment -

Great idea, thx for the patch!

Show
Alex Miller added a comment - Great idea, thx for the patch!
Hide
Alex Miller added a comment -

Would be great to see a before and after example of the output.

Show
Alex Miller added a comment - Would be great to see a before and after example of the output.
Hide
Ivan Kozik added a comment -

Attaching sample output

Show
Ivan Kozik added a comment - Attaching sample output
Hide
Stuart Sierra added a comment -

As pointed out on IRC, there's a possible risk of trying to print an infinite lazy sequence that happened to be included in ex-data.

To mitigate, consider binding *print-length* and *print-level* to small numbers around the call to pr.

Show
Stuart Sierra added a comment - As pointed out on IRC, there's a possible risk of trying to print an infinite lazy sequence that happened to be included in ex-data. To mitigate, consider binding *print-length* and *print-level* to small numbers around the call to pr.
Hide
Stephen C. Gilardi added a comment -

http://dev.clojure.org/jira/browse/CLJ-1716 may cover this well enough that this issue can be closed.

Show
Stephen C. Gilardi added a comment - http://dev.clojure.org/jira/browse/CLJ-1716 may cover this well enough that this issue can be closed.
Hide
Alex Miller added a comment - - edited

I don't think 1716 covers it at all as clojure.test/clojure.stacktrace don't use the new throwable printing. But they could! And that might be a better solution than the patch here.

For example, the existing patch does not consider what to do about nested exceptions, some of which might have ex-data. The new printer handles all that in a consistent way.

Show
Alex Miller added a comment - - edited I don't think 1716 covers it at all as clojure.test/clojure.stacktrace don't use the new throwable printing. But they could! And that might be a better solution than the patch here. For example, the existing patch does not consider what to do about nested exceptions, some of which might have ex-data. The new printer handles all that in a consistent way.

People

Vote (4)
Watch (1)

Dates

  • Created:
    Updated: