You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am adding a new automated test(s) to verify correctness of my new code
I am adding new logging messages
I am adding a new telemetry message
I am modifying authorization mechanisms
I am adding new credentials
I am modifying OCSP code
I am adding a new dependency
Please describe how your code solves the related issue.
This change aligns the connector’s structured error-handling API with the contract already used in errors.py.
It introduces a shared structured payload type for error details and a shared protocol for error handlers, then applies that contract to the sync connection and cursor errorhandler attributes. It also narrows the structured error-handler flow to Snowflake Error subclasses only.
In addition, it updates errorhandler_wrapper_from_ready_exception() so generic Python exceptions are re-raised directly instead of being routed into the dict-based structured handler path. This avoids the inconsistent case described in SNOW-3246741: Align structured error-handler typing and ready-exception handling #2790, where non-Snowflake exceptions could enter a handler flow that expects structured error details.
The PR also adds unit tests covering:
- default structured error handling
- forwarding structured payloads to custom handlers
- normalization of ready Error instances
- direct re-raise behavior for generic exceptions
Behavioral change in errorhandler_wrapper_from_ready_exception may bypass custom error handlers
The old implementation of errorhandler_wrapper_from_ready_exception routed all exceptions (including non-Error ones) through hand_to_other_handler, which would forward them to any custom errorhandler set on the cursor or connection. The new code immediately re-raises non-Error exceptions, skipping custom handlers entirely:
# New behaviorifnotisinstance(error_exc, Error):
raiseerror_exc
The callers in cursor.py, aio/_cursor.py, and aio/_result_set.py all use isinstance(_next, Exception) as the guard, meaning arbitrary exceptions could flow in. In practice these exceptions come from Error.errorhandler_make_exception(InterfaceError, ...) in result_batch.py, so they should always be Error subclasses. But if any edge case produces a raw Exception, the behavior change would be user-visible:
Custom error handlers on cursor/connection would no longer see the exception
The messages list on cursor/connection wouldn't be appended to
The exception would bubble up raw instead of going through the handler chain
This is probably safe in practice, but it might be worth calling out explicitly as a deliberate behavior change — especially for anyone relying on custom errorhandler callbacks to intercept all exceptions.
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
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.
Please answer these questions before submitting your pull requests. Thanks!
What GitHub issue is this PR addressing? Make sure that there is an accompanying issue to your PR.
Fixes SNOW-3246741: Align structured error-handler typing and ready-exception handling #2790
Fill out the following pre-review checklist:
Please describe how your code solves the related issue.
This change aligns the connector’s structured error-handling API with the contract already used in
errors.py.It introduces a shared structured payload type for error details and a shared protocol for error handlers, then applies that contract to the sync connection and cursor
errorhandlerattributes. It also narrows the structured error-handler flow to SnowflakeErrorsubclasses only.In addition, it updates
errorhandler_wrapper_from_ready_exception()so generic Python exceptions are re-raised directly instead of being routed into the dict-based structured handler path. This avoids the inconsistent case described in SNOW-3246741: Align structured error-handler typing and ready-exception handling #2790, where non-Snowflake exceptions could enter a handler flow that expects structured error details.The PR also adds unit tests covering:
- default structured error handling
- forwarding structured payloads to custom handlers
- normalization of ready
Errorinstances- direct re-raise behavior for generic exceptions
(Optional) PR for stored-proc connector: