java.jdbc

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

Details

  • Type: Enhancement Enhancement
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • 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)

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

Activity

Hide
Sean Corfield added a comment -

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.

Show
Sean Corfield added a comment - 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.
Hide
Sean Corfield added a comment -

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.

Show
Sean Corfield added a comment - 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.
Hide
Sean Corfield added a comment -

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.

Show
Sean Corfield added a comment - 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.
Hide
Sean Corfield added a comment -

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.

Show
Sean Corfield added a comment - 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.
Hide
Sean Corfield added a comment -

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

Show
Sean Corfield added a comment - Fixed in upcoming 0.5.0 (which drops Clojure 1.3.0 support).
Hide
Christopher Jeris added a comment -

That was fast! Thank you very much!

Show
Christopher Jeris added a comment - That was fast! Thank you very much!
Hide
Sean Corfield added a comment -

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

Show
Sean Corfield added a comment - 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).

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: