Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TrinoQueryError::error_location optional #535

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

stephen-zhao
Copy link

Description

Fix #534 by making TrinoQueryError::error_location using get instead of [] to return an optional tuple.

Non-technical explanation

Make TrinoQueryError::error_location exception-safe when no error_location is available.

Release notes

( ) This is not user-visible or docs only and no release notes are required.
( ) Release notes are required, please propose a release note for me.
(x) Release notes are required, with the following suggested text:

* Fix `KeyError` when accessing missing `error_location` in `TrinoQueryError` ({issue}`534`)

Copy link

cla-bot bot commented Feb 18, 2025

Thank you for your pull request and welcome to the Trino community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. Continue to work with us on the review and improvements in this PR, and submit the signed CLA to [email protected]. Photos, scans, or digitally-signed PDF files are all suitable. Processing may take a few days. The CLA needs to be on file before we merge your changes. For more information, see https://github.com/trinodb/cla

@stephen-zhao stephen-zhao changed the title Make error_location optional Make TrinoQueryError::error_location optional Feb 18, 2025
return (location["lineNumber"], location["columnNumber"])
def error_location(self) -> Optional[Tuple[int, int]]:
location = self._error.get("errorLocation", None)
return (location["lineNumber"], location["columnNumber"]) if location else None
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could use get for these sub-accesses as well.. and have the whole thing get eaten up by a null if anything doesn't exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please do so. Then we will be consistent in using get over [].

@hashhar
Copy link
Member

hashhar commented Feb 26, 2025

@cla-bot check

This comment was marked as outdated.

This comment was marked as outdated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Exception-Safety of TrinoUserError::error_location
3 participants