From 1abc8e8cfb7b00c4b608b1597d231d160dccec21 Mon Sep 17 00:00:00 2001 From: Dalena Date: Fri, 1 Nov 2024 14:45:00 -0500 Subject: [PATCH 1/4] fix: raise UsageError --- silverback/cluster/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/silverback/cluster/client.py b/silverback/cluster/client.py index ff4cfc5b..ce63d94e 100644 --- a/silverback/cluster/client.py +++ b/silverback/cluster/client.py @@ -2,6 +2,7 @@ from functools import cache from typing import ClassVar, Literal +import click import httpx from ape import Contract from ape.contracts import ContractInstance @@ -54,7 +55,7 @@ def render_error(error: dict): else: message = response.text - raise RuntimeError(message) + raise click.UsageError(message) response.raise_for_status() From a50aba60587a783fa87f7478bb448a77baf3aea9 Mon Sep 17 00:00:00 2001 From: Dalena Date: Fri, 1 Nov 2024 15:05:04 -0500 Subject: [PATCH 2/4] refactor: ClientError --- silverback/cluster/client.py | 4 ++-- silverback/exceptions.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/silverback/cluster/client.py b/silverback/cluster/client.py index ce63d94e..4ed51f1a 100644 --- a/silverback/cluster/client.py +++ b/silverback/cluster/client.py @@ -2,7 +2,6 @@ from functools import cache from typing import ClassVar, Literal -import click import httpx from ape import Contract from ape.contracts import ContractInstance @@ -12,6 +11,7 @@ from silverback.version import version +from .exceptions import ClientError from .types import ( BotHealth, BotInfo, @@ -55,7 +55,7 @@ def render_error(error: dict): else: message = response.text - raise click.UsageError(message) + raise ClientError(message) response.raise_for_status() diff --git a/silverback/exceptions.py b/silverback/exceptions.py index 554f5a88..2fa53d9c 100644 --- a/silverback/exceptions.py +++ b/silverback/exceptions.py @@ -1,5 +1,6 @@ from typing import Any +import click from ape.exceptions import ApeException from .types import TaskType @@ -41,6 +42,10 @@ def __init__(self, *exceptions: Exception | str): super().__init__("Startup failure(s) detected. See logs for details.") +class ClientError(SilverbackException, click.UsageError): + """Exception for client errors in the HTTP request.""" + + class NoTasksAvailableError(SilverbackException): def __init__(self): super().__init__("No tasks to execute") From 1ad9353efa8e6e4816d45d3c8add27f6fb89df24 Mon Sep 17 00:00:00 2001 From: Dalena Date: Fri, 1 Nov 2024 15:12:03 -0500 Subject: [PATCH 3/4] fix: import --- silverback/cluster/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/silverback/cluster/client.py b/silverback/cluster/client.py index 4ed51f1a..a3a6c563 100644 --- a/silverback/cluster/client.py +++ b/silverback/cluster/client.py @@ -9,9 +9,9 @@ from apepay import Stream, StreamManager from pydantic import computed_field +from silverback.exceptions import ClientError from silverback.version import version -from .exceptions import ClientError from .types import ( BotHealth, BotInfo, From 61fa711f4b26437ed7db7c95c73d3e5b84adca8a Mon Sep 17 00:00:00 2001 From: Dalena Date: Fri, 1 Nov 2024 15:56:43 -0500 Subject: [PATCH 4/4] fix: add note --- silverback/exceptions.py | 1 + 1 file changed, 1 insertion(+) diff --git a/silverback/exceptions.py b/silverback/exceptions.py index 2fa53d9c..ffc6c6d3 100644 --- a/silverback/exceptions.py +++ b/silverback/exceptions.py @@ -42,6 +42,7 @@ def __init__(self, *exceptions: Exception | str): super().__init__("Startup failure(s) detected. See logs for details.") +# NOTE: Subclass `click.UsageError` here so bad requests in CLI don't show stack trace class ClientError(SilverbackException, click.UsageError): """Exception for client errors in the HTTP request."""