Skip to content

Improve QueryFailedError #85

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changes/unreleased/Under the Hood-20250616-101046.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Under the Hood
body: add error, status, and query_id to QueryFailedError
time: 2025-06-16T10:10:46.504635-06:00
2 changes: 1 addition & 1 deletion dbtsl/api/adbc/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _handle_error(self, err: Exception) -> None:
raise AuthError(err.args) from err

if err.status_code == AdbcStatusCode.INVALID_ARGUMENT:
raise QueryFailedError(err.args) from err
raise QueryFailedError(err.details, err.status_code) from err

# TODO: timeouts are not implemented for ADBC
# See: https://arrow.apache.org/adbc/current/driver/flight_sql.html#timeouts
Expand Down
2 changes: 1 addition & 1 deletion dbtsl/api/graphql/client/asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ async def query(self, **params: Unpack[QueryParameters]) -> "pa.Table":
variables={"query_id": query_id, "page_num": 1},
)
if first_page_results.status != QueryStatus.SUCCESSFUL:
raise QueryFailedError()
raise QueryFailedError(first_page_results.error, first_page_results.status, query_id)

assert first_page_results.total_pages is not None

Expand Down
2 changes: 1 addition & 1 deletion dbtsl/api/graphql/client/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def query(self, **params: Unpack[QueryParameters]) -> "pa.Table":
},
)
if first_page_results.status != QueryStatus.SUCCESSFUL:
raise QueryFailedError()
raise QueryFailedError(first_page_results.error, first_page_results.status, query_id)

assert first_page_results.total_pages is not None

Expand Down
22 changes: 22 additions & 0 deletions dbtsl/error.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import json
from typing import Any, Optional


class SemanticLayerError(RuntimeError):
Expand Down Expand Up @@ -46,6 +47,27 @@ class RetryTimeoutError(TimeoutError):
class QueryFailedError(SemanticLayerError):
"""Raise whenever a query has failed."""

def __init__(self, message: Any, status: Any, query_id: Optional[str] = None) -> None:
"""Initialize the query failed error.

Args:
message: The message or error details
status: The stringified status or the response
query_id: The query ID for GQL requests
"""
# extract first error message if we get a list with just 1 message
if isinstance(message, list) and len(message) == 1: # pyright: ignore
message = message[0] # pyright: ignore
self.message = str(message) # pyright: ignore
self.status = str(status)
self.query_id = query_id

def __str__(self) -> str: # noqa: D105
content = f"message=\"{self.message}\"), status={self.status}"
if self.query_id:
content += f", query_id={self.query_id}"
return f"{self.__class__.__name__}({content})"


class AuthError(SemanticLayerError):
"""Raise whenever there was a problem authenticating to the API."""
Loading