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

Stuart Sierra made changes -
Field Original Value New Value
Description When clojure.test/deftest does error reports on unexpected exceptions it currently ignores ExceptionInfo and the valuable ex-data it carries. So this patch simple prints this data, it might be helpful to pprint or format it in another way but this was good enough for me.

See example from my tests: https://gist.github.com/thheller/5559391

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

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

*Patch:* 0002-CLJ-1209-show-ex-data-in-clojure-test.patch
Attachment 0002-CLJ-1209-show-ex-data-in-clojure-test.patch [ 12545 ]
Stuart Sierra made changes -
Summary Teach clojure.test reporting about ex-info/ex-data clojure.test does not print ex-info in error reports
Alex Miller made changes -
Approval Triaged [ 10120 ]
Alex Miller made changes -
Priority Trivial [ 5 ] Minor [ 4 ]
Ivan Kozik made changes -
Attachment output-with-0002-patch.txt [ 13128 ]
Alex Miller made changes -
Priority Minor [ 4 ] Major [ 3 ]
Alex Miller made changes -
Priority Major [ 3 ] Critical [ 2 ]
Alex Miller made changes -
Labels clojure.test
Alex Miller made changes -
Description {{clojure.test}} does not print the data attached to ExceptionInfo in error reports.

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

*Patch:* 0002-CLJ-1209-show-ex-data-in-clojure-test.patch
{{clojure.test}} does not print the data attached to ExceptionInfo in error reports.

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

ERROR in (ex-test) (AFn.java:429)
Uncaught exception, not in assertion.
expected: nil
  actual: clojure.lang.ArityException: Wrong number of args (1) passed to: core/ex-info
 at clojure.lang.AFn.throwArity (AFn.java:429)
    clojure.lang.AFn.invoke (AFn.java:32)
    user/fn (NO_SOURCE_FILE:6)
    clojure.test$test_var$fn__7666.invoke (test.clj:704)
    ...
{code}

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

After:
{code}
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)
{code}

*Patch:* 0002-CLJ-1209-show-ex-data-in-clojure-test.patch
Alex Miller made changes -
Description {{clojure.test}} does not print the data attached to ExceptionInfo in error reports.

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

ERROR in (ex-test) (AFn.java:429)
Uncaught exception, not in assertion.
expected: nil
  actual: clojure.lang.ArityException: Wrong number of args (1) passed to: core/ex-info
 at clojure.lang.AFn.throwArity (AFn.java:429)
    clojure.lang.AFn.invoke (AFn.java:32)
    user/fn (NO_SOURCE_FILE:6)
    clojure.test$test_var$fn__7666.invoke (test.clj:704)
    ...
{code}

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

After:
{code}
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)
{code}

*Patch:* 0002-CLJ-1209-show-ex-data-in-clojure-test.patch
{{clojure.test}} does not print the data attached to ExceptionInfo in error reports.

{code}
(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)
    ...
{code}

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

After:
{code}
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)
{code}

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

People

Vote (4)
Watch (1)

Dates

  • Created:
    Updated: