From cb7b8ec2af12a7bd111612cfa93b8c98a28b3197 Mon Sep 17 00:00:00 2001 From: RotemFB Date: Mon, 10 Jul 2023 14:40:46 +0300 Subject: [PATCH 1/3] Now showing error body when something goes wrong --- src/firebolt/async_db/cursor.py | 7 +++++++ src/firebolt/db/cursor.py | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/firebolt/async_db/cursor.py b/src/firebolt/async_db/cursor.py index 890e71674a7..6346128c2ab 100644 --- a/src/firebolt/async_db/cursor.py +++ b/src/firebolt/async_db/cursor.py @@ -40,6 +40,7 @@ CursorClosedError, EngineNotRunningError, FireboltDatabaseError, + FireboltError, OperationalError, ProgrammingError, QueryNotRunError, @@ -133,6 +134,12 @@ async def _raise_if_error(self, resp: Response) -> None: f"Firebolt engine {self.connection.engine_url} " "needs to be running to run queries against it." ) + if ( + codes.is_error(resp.status_code) + and "Content-Length" in resp.headers + and int(resp.headers["Content-Length"]) > 0 + ): + raise FireboltError(f"Something went wrong: {resp.read().decode('utf-8')}") resp.raise_for_status() async def _api_request( diff --git a/src/firebolt/db/cursor.py b/src/firebolt/db/cursor.py index 69c84a81115..a414b8cdb3c 100644 --- a/src/firebolt/db/cursor.py +++ b/src/firebolt/db/cursor.py @@ -42,6 +42,7 @@ AsyncExecutionUnavailableError, EngineNotRunningError, FireboltDatabaseError, + FireboltError, OperationalError, ProgrammingError, ) @@ -101,6 +102,12 @@ def _raise_if_error(self, resp: Response) -> None: f"Firebolt engine {self.connection.engine_url} " "needs to be running to run queries against it." ) + if ( + codes.is_error(resp.status_code) + and "Content-Length" in resp.headers + and int(resp.headers["Content-Length"]) > 0 + ): + raise FireboltError(f"Something went wrong: {resp.read().decode('utf-8')}") resp.raise_for_status() def _api_request( From caee9f50b2150d460d3b0a3087f98f9bea66aa24 Mon Sep 17 00:00:00 2001 From: RotemFB Date: Wed, 12 Jul 2023 11:02:59 +0300 Subject: [PATCH 2/3] the error body is now being shown in the log --- src/firebolt/async_db/cursor.py | 3 +-- src/firebolt/db/cursor.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/firebolt/async_db/cursor.py b/src/firebolt/async_db/cursor.py index 6346128c2ab..35d3e36207b 100644 --- a/src/firebolt/async_db/cursor.py +++ b/src/firebolt/async_db/cursor.py @@ -40,7 +40,6 @@ CursorClosedError, EngineNotRunningError, FireboltDatabaseError, - FireboltError, OperationalError, ProgrammingError, QueryNotRunError, @@ -139,7 +138,7 @@ async def _raise_if_error(self, resp: Response) -> None: and "Content-Length" in resp.headers and int(resp.headers["Content-Length"]) > 0 ): - raise FireboltError(f"Something went wrong: {resp.read().decode('utf-8')}") + logger.debug(f"Something went wrong: {resp.read().decode('utf-8')}") resp.raise_for_status() async def _api_request( diff --git a/src/firebolt/db/cursor.py b/src/firebolt/db/cursor.py index a414b8cdb3c..8790fdef8e8 100644 --- a/src/firebolt/db/cursor.py +++ b/src/firebolt/db/cursor.py @@ -42,7 +42,6 @@ AsyncExecutionUnavailableError, EngineNotRunningError, FireboltDatabaseError, - FireboltError, OperationalError, ProgrammingError, ) @@ -107,7 +106,7 @@ def _raise_if_error(self, resp: Response) -> None: and "Content-Length" in resp.headers and int(resp.headers["Content-Length"]) > 0 ): - raise FireboltError(f"Something went wrong: {resp.read().decode('utf-8')}") + logger.debug(f"Something went wrong: {resp.read().decode('utf-8')}") resp.raise_for_status() def _api_request( From 091f8c975295d219a7272a90dcd6a97beafb6a35 Mon Sep 17 00:00:00 2001 From: RotemFB Date: Wed, 12 Jul 2023 13:06:54 +0300 Subject: [PATCH 3/3] try - except when checking for the error body --- src/firebolt/async_db/cursor.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/firebolt/async_db/cursor.py b/src/firebolt/async_db/cursor.py index 35d3e36207b..783cc931364 100644 --- a/src/firebolt/async_db/cursor.py +++ b/src/firebolt/async_db/cursor.py @@ -133,12 +133,15 @@ async def _raise_if_error(self, resp: Response) -> None: f"Firebolt engine {self.connection.engine_url} " "needs to be running to run queries against it." ) - if ( - codes.is_error(resp.status_code) - and "Content-Length" in resp.headers - and int(resp.headers["Content-Length"]) > 0 - ): - logger.debug(f"Something went wrong: {resp.read().decode('utf-8')}") + try: + if ( + codes.is_error(resp.status_code) + and "Content-Length" in resp.headers + and int(resp.headers["Content-Length"]) > 0 + ): + logger.debug(f"Something went wrong: {resp.read().decode('utf-8')}") + except Exception: + pass resp.raise_for_status() async def _api_request(