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

Wrap all requests.exceptions.RequestException as TrinoConnectionError #393

Conversation

Shaheer-rossoneri14
Copy link
Member

@Shaheer-rossoneri14 Shaheer-rossoneri14 commented Jul 18, 2023

Description

Wrap all requests.exceptions.RequestException as TrinoConnectionError.
Fixes #364.

Non-technical explanation

Before this change if a user needed to catch connection errors (e.g. connection refused) they needed to add a dependency on requests and import the relevant exception from requests.exceptions module.

After this change all requests exception get rethrown as a TrinoConnectionError instead.

Release notes

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

* Fix some things. ({issue}`issuenumber`)

@cla-bot
Copy link

cla-bot bot commented Jul 18, 2023

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 cla@trino.io. 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

Copy link
Member

@hovaesco hovaesco left a comment

Choose a reason for hiding this comment

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

LGTM

try:
response = self._request.post(self._query, additional_http_headers)
except requests.exceptions.RequestException as e:
raise trino.exceptions.TrinoConnectionError("failed to execute: {}".format(e))
Copy link
Contributor

@mdesmet mdesmet Jul 27, 2023

Choose a reason for hiding this comment

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

I think a OperationalError is more at its place here.

This also applies to the other places where you wrap this exception, otherwise it would not be captured by other frameworks like sqlalchemy.

Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

Please apply changes from #393 (comment)

LGTM otherwise.

@cla-bot cla-bot bot added the cla-signed label Aug 6, 2023
@Shaheer-rossoneri14
Copy link
Member Author

@hovaesco @mdesmet @hashhar Please take a look at the fixup commit.

I made the TrinoConnectionError a subclass of OperationalError. This way frameworks can catch OperationalError while users can also catch TrinoConnectionError for more fine-grained handling if needed.

Copy link
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

LGTM.

Please squash the fixups @Shaheer-rossoneri14.

Before this change if a user needed to catch connection errors (e.g.
connection refused) they needed to add a dependency on requests and
import the relevant exception from requests.exceptions module.

After this change all requests exception get rethrown as a
TrinoConnectionError instead.
@Shaheer-rossoneri14 Shaheer-rossoneri14 force-pushed the Shaheer-rossoneri14/trino-connection-error branch from 771163f to e0cf1f2 Compare August 26, 2023 16:39
@Shaheer-rossoneri14
Copy link
Member Author

@hashhar I have squashed the fixups.

@hashhar hashhar merged commit 47bbdd8 into trinodb:master Aug 28, 2023
11 checks passed
@Shaheer-rossoneri14 Shaheer-rossoneri14 deleted the Shaheer-rossoneri14/trino-connection-error branch September 2, 2023 07:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Give Trino an exception type for connection errors
4 participants