Fix: improve Java exception error messages with cause chain (legacy #250)#81
Open
HenryNebula wants to merge 3 commits intodevfrom
Open
Fix: improve Java exception error messages with cause chain (legacy #250)#81HenryNebula wants to merge 3 commits intodevfrom
HenryNebula wants to merge 3 commits intodevfrom
Conversation
e69f93c to
aa1af12
Compare
…250) - Add _build_java_exception_message() to extract clean class name, message, and walk the getCause() chain for informative error output - Avoid JPype 1.7.0+ duplicated class-name artefact by using getClass().getName() instead of str(exc) - Wrap prepareStatement() and executeBatch() in try/except so Java exceptions from these calls are properly handled as DB-API errors Fixes #80 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The test_sql_exception_message_is_clean test was asserting HSQLDB-specific exception class names (SQLSyntaxErrorException), which failed on MSSQL (SQLServerException), Oracle, Trino, etc. Make assertions generic to work across all JDBC drivers. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Oracle uses ORA-00942 instead of table name in error messages. Remove table-name assertion and add Oracle-specific duplication check. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
aa1af12 to
87e3329
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #80: Java exceptions from JDBC drivers now produce clean, informative error messages that include the full cause chain.
Previously, when a JDBC driver threw a non-SQLException (e.g.,
RuntimeException), the error message was uninformative — users would see generic "Java Exception" without context about the root cause. Additionally, JPype 1.7.0+ introduced duplicated class-name prefixes (e.g.,java.lang.java.lang.RuntimeException).Changes
_build_java_exception_message()to extract clean class name, message, and walk thegetCause()chain for informative error outputgetClass().getName()instead ofstr(exc)prepareStatement()andexecuteBatch()in try/except so Java exceptions from these calls are properly handled as DB-API errors (previously they propagated raw)mockExceptionOnExecuteWithCause()to MockDriver for testing cause chainsTest plan
CLASSPATH="test/jars/*:test/mock-jars/*" uv run python -m unittest test.test_mock(62 tests)CLASSPATH="test/jars/*" uv run python -m unittest test.test_integration.HsqldbTest(17 tests)Closes #80
Generated with Claude Code