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

refactor: fix error messages #51

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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-20241008-160709.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
kind: Under the Hood
body: Improve error display
time: 2024-10-08T16:07:09.766189+02:00
6 changes: 3 additions & 3 deletions dbtsl/api/adbc/client/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ def _get_connection_context_manager(self) -> AbstractContextManager[Connection]:
def _handle_error(self, err: Exception) -> None:
if isinstance(err, ProgrammingError):
if err.status_code in (AdbcStatusCode.UNAUTHENTICATED, AdbcStatusCode.UNAUTHORIZED):
raise AuthError(err.args)
raise AuthError(err.args) from err

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

# TODO: timeouts are not implemented for ADBC
# See: https://arrow.apache.org/adbc/current/driver/flight_sql.html#timeouts
if err.status_code == AdbcStatusCode.TIMEOUT:
raise TimeoutError()
raise TimeoutError() from err

raise err

Expand Down
6 changes: 5 additions & 1 deletion dbtsl/error.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import json


class SemanticLayerError(RuntimeError):
"""Any errors related to the Semantic Layer inherit from this."""

def __str__(self) -> str:
"""RuntimeError doesn't stringify itself by default, so we need to manually add this."""
return self.__class__.__name__
args_str = "" if len(self.args) == 0 else ", ".join(json.dumps(a) for a in self.args)
return f"{self.__class__.__name__}({args_str})"

def __repr__(self) -> str:
"""RuntimeError doesn't stringify itself by default, so we need to manually add this."""
Expand Down
12 changes: 8 additions & 4 deletions tests/test_error.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
from dbtsl.error import SemanticLayerError, TimeoutError


def test_error_str() -> None:
assert str(SemanticLayerError()) == "SemanticLayerError"
def test_error_str_calls_repr() -> None:
assert str(SemanticLayerError()) == repr(SemanticLayerError())


def test_error_repr() -> None:
assert repr(SemanticLayerError()) == "SemanticLayerError"
def test_error_repr_no_args() -> None:
assert repr(SemanticLayerError()) == "SemanticLayerError()"


def test_error_repr_with_args() -> None:
assert repr(SemanticLayerError(1, 2, "a")) == 'SemanticLayerError(1, 2, "a")'


def test_timeout_error_str() -> None:
Expand Down