<< Back to previous view

[JDBC-114] ex-info thrown inside with-db-transaction is not preserved Created: 23/Nov/15  Updated: 01/Jun/16  Resolved: 23/Nov/15

Status: Closed
Project: java.jdbc
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Christopher Jeris Assignee: Sean Corfield
Resolution: Completed Votes: 0
Labels: None

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


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.)

Comment by Sean Corfield [ 23/Nov/15 5:07 PM ]

The original reason for this was that the Clojure runtime auto-wrapped exceptions so your java.jdbc code might throw a SQLException but you couldn't catch it directly because it got turned into a RuntimeException instead. That was added a very long time ago. I'd have to see when Clojure stopped wrapping RTEs to see whether that could be removed – otherwise I'd have to special case ExceptionInfo in there instead.

Comment by Sean Corfield [ 23/Nov/15 5:13 PM ]

It relates to this http://dev.clojure.org/jira/browse/CLJ-855 so it looks like I could remove it if I dropped support for Clojure 1.3.0. I only dropped support for 1.2.x in September but that's definitely a possibility.

Comment by Sean Corfield [ 23/Nov/15 5: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.

Comment by Sean Corfield [ 23/Nov/15 5: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.

Comment by Sean Corfield [ 23/Nov/15 5:57 PM ]

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

Comment by Christopher Jeris [ 24/Nov/15 9:06 AM ]

That was fast! Thank you very much!

Comment by Sean Corfield [ 24/Nov/15 10:40 AM ]

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).

Generated at Mon Feb 19 23:46:37 CST 2018 using JIRA 4.4#649-r158309.