Skip to content

Fix: improve Java exception error messages with cause chain (legacy #250)#81

Open
HenryNebula wants to merge 3 commits intodevfrom
worktree-triage+80-informative-exceptions
Open

Fix: improve Java exception error messages with cause chain (legacy #250)#81
HenryNebula wants to merge 3 commits intodevfrom
worktree-triage+80-informative-exceptions

Conversation

@HenryNebula
Copy link
Copy Markdown
Owner

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

  • 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 (previously they propagated raw)
  • Add mockExceptionOnExecuteWithCause() to MockDriver for testing cause chains
  • Add mock tests for cause chain inclusion and no duplicate classnames
  • Add integration test verifying SQL exceptions produce clean messages with cause chain

Test plan

  • Added mock test reproducing RuntimeException with nested cause
  • Added mock test verifying no duplicate class names in error messages
  • Added integration test verifying SQL exceptions include cause chain
  • Verified fix passes with CLASSPATH="test/jars/*:test/mock-jars/*" uv run python -m unittest test.test_mock (62 tests)
  • Verified fix passes with CLASSPATH="test/jars/*" uv run python -m unittest test.test_integration.HsqldbTest (17 tests)

Closes #80

Generated with Claude Code

HenryNebula and others added 3 commits April 28, 2026 09:08
…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>
@HenryNebula HenryNebula force-pushed the worktree-triage+80-informative-exceptions branch from aa1af12 to 87e3329 Compare April 28, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant