Skip to content

Commit b5e3a39

Browse files
committed
feat: better error reporting on SQL session creation errors
1 parent 448487d commit b5e3a39

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

tests/smoke.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from rich.console import Console
1111
from rich.table import Table
1212

13-
from wherobots.db import connect, connect_direct
13+
from wherobots.db import connect, connect_direct, errors
1414
from wherobots.db.constants import DEFAULT_ENDPOINT, DEFAULT_SESSION_TYPE
1515
from wherobots.db.connection import Connection
1616
from wherobots.db.region import Region
@@ -103,8 +103,12 @@ def execute(conn: Connection, sql: str) -> pandas.DataFrame:
103103
cursor.execute(sql)
104104
return cursor.fetchall()
105105

106-
with conn_func() as conn:
107-
with concurrent.futures.ThreadPoolExecutor() as pool:
108-
futures = [pool.submit(execute, conn, s) for s in args.sql]
109-
for future in concurrent.futures.as_completed(futures):
110-
render(future.result())
106+
try:
107+
with conn_func() as conn:
108+
with concurrent.futures.ThreadPoolExecutor() as pool:
109+
futures = [pool.submit(execute, conn, s) for s in args.sql]
110+
for future in concurrent.futures.as_completed(futures):
111+
render(future.result())
112+
except errors.Error as e:
113+
sys.stderr.write(f"\n{e}\n")
114+
sys.exit(1)

wherobots/db/driver.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ def connect(
116116
)
117117
resp.raise_for_status()
118118
except requests.HTTPError as e:
119-
raise InterfaceError("Failed to create SQL session!", e)
119+
details = str(e)
120+
try:
121+
info = e.response.json()
122+
errors = info.get("errors", [])
123+
if errors and isinstance(errors, list):
124+
details = f"{errors[0]['message']}: {errors[0]['details']}"
125+
except requests.JSONDecodeError:
126+
pass
127+
raise InterfaceError(f"Failed to create SQL session: {details}") from e
120128

121129
# At this point we've been redirected to /sql/session/{session_id}, which we'll need to keep polling until the
122130
# session is in READY state.

0 commit comments

Comments
 (0)