Skip to content

Fix: wrap JDBC exceptions during fetch as DatabaseError (legacy #58)#83

Open
HenryNebula wants to merge 1 commit intodevfrom
worktree-triage+82-divide-by-zero-exc
Open

Fix: wrap JDBC exceptions during fetch as DatabaseError (legacy #58)#83
HenryNebula wants to merge 1 commit intodevfrom
worktree-triage+82-divide-by-zero-exc

Conversation

@HenryNebula
Copy link
Copy Markdown
Owner

Summary

Fixes #82: JDBC driver exceptions during data retrieval (e.g., divide-by-zero in calculated columns) now properly raise Python DatabaseError instead of raw Java exceptions.

Changes

  • Walk the cause chain in _handle_sql_exception_jpype() to detect SQLException even when wrapped by Arrow's JdbcConsumerException
  • Wire _handle_sql_exception into fetch_next_batch() and read_rows_from_arrow_iterator() so fetch-time errors become proper Python DatabaseError
  • Add mockExceptionOnFetch() to MockConnection for testing
  • Add 3 mock tests for SQLException/RuntimeException during fetch
  • Add HSQLDB integration test for division-by-zero error handling

Test plan

  • Added mock test cases reproducing the reported bug (SQLException and RuntimeException during fetchone/fetchall)
  • Added HSQLDB integration test for division-by-zero
  • Verified fix passes all 63 mock tests and 17 HSQLDB integration tests

Closes #82

Generated with Claude Code

When a JDBC driver throws an exception during data retrieval (e.g.,
divide-by-zero in calculated columns), the raw Java exception now
propagates through the Arrow JDBC library wrapped in
JdbcConsumerException. Previously these were re-raised as raw Java
exceptions to the Python caller.

Changes:
- Walk the cause chain in _handle_sql_exception_jpype() to detect
  SQLException even when wrapped by JdbcConsumerException
- Wire _handle_sql_exception into fetch_next_batch() and
  read_rows_from_arrow_iterator() so fetch-time errors become proper
  Python DatabaseError instead of raw Java exceptions
- Add mockExceptionOnFetch() to MockConnection for testing
- Add mock tests for SQLException and RuntimeException during fetch
- Add HSQLDB integration test for division-by-zero error handling

Fixes #82

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@HenryNebula HenryNebula force-pushed the worktree-triage+82-divide-by-zero-exc branch from 103f96a to bedf004 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