Skip to content

Wrap all requests.exceptions.RequestException as TrinoConnectionError - #393

Merged
hashhar merged 1 commit into
trinodb:masterfrom
Shaheer-rossoneri14:Shaheer-rossoneri14/trino-connection-error
Aug 28, 2023
Merged

Wrap all requests.exceptions.RequestException as TrinoConnectionError#393
hashhar merged 1 commit into
trinodb:masterfrom
Shaheer-rossoneri14:Shaheer-rossoneri14/trino-connection-error

Conversation

@Shaheer-rossoneri14

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

Copy link
Copy Markdown
Member

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

cla-bot Bot commented Jul 18, 2023

Copy link
Copy Markdown

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

@hovaesco hovaesco left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread trino/client.py
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))

@mdesmet mdesmet Jul 27, 2023

Copy link
Copy Markdown
Contributor

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.

@hashhar hashhar left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
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.

@hashhar hashhar left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member Author

@hashhar I have squashed the fixups.

@hashhar
hashhar merged commit 47bbdd8 into trinodb:master Aug 28, 2023
@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