ex-info thrown inside with-db-transaction is not preserved

Description

I have a with-db-transaction block surrounding several queries, where in case one of them fails I would like to attach some locally known metadata about the individual query using ex-info. Unfortunately the clojure.java.jdbc/db-transaction* macro uses clojure.java.jdbc/throw-non-rte to strip off all the layers of RuntimeException around a thrown SQLException. Since clojure.lang.ExceptionInfo is a RuntimeException, this means that my metadata does not survive to the outside of the with-db-transaction macro, unless I defeat the intent of JVM exception handling by passing the original SQLException somewhere other than the cause field of my wrapper exception.

  • Is this RuntimeException stripping behavior mentioned in the public facing documentation for clojure.java.jdbc?

  • Is it feasible from a design point of view to suppress this behavior, either on a switch, or for ExceptionInfo only, or both?

(I am happy to supply a patch myself if you judge this an appropriate enhancement.)

Environment

Clojure 1.7.0, java.jdbc 0.3.7 (same issue exists in 0.4.2 but my active environment uses 0.3.7)

Activity

Show:

Sean CorfieldNovember 24, 2015 at 4:40 PM

Well, I don't know yet when 0.5.0 will be released, but you can try out the snapshot from Sonatype in the meantime if you want. Since I'm going from 0.4.x to 0.5.0, I may well make some other breaking changes (such as removing the deprecated namespace and maybe tackling the reducer stuff – which would also drop support for 1.4 I think).

importNovember 24, 2015 at 3:06 PM

Comment made by: cjeris

That was fast! Thank you very much!

Sean CorfieldNovember 23, 2015 at 11:57 PM

Fixed in upcoming 0.5.0 (which drops Clojure 1.3.0 support).

Sean CorfieldNovember 23, 2015 at 11:49 PM

Test added that reproduces the wrapped exception behavior and it occurs in 1.3.0 only so I'll drop support for that but bump the version to 0.5.0.

Sean CorfieldNovember 23, 2015 at 11:24 PM

I removed throw-non-rte and my tests do not fail for Clojure 1.3.0 which makes me think my tests are not comprehensive enough. I want to see if I can reproduce the wrapping for 1.3.0 in a test before I try to close this.

Completed

Details

Assignee

Reporter

Priority

Created November 23, 2015 at 9:28 PM
Updated June 1, 2016 at 6:41 PM
Resolved June 1, 2016 at 6:41 PM