From a2ddac75f3280062f07fb77ae1a67b286b61dddf Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 1 Nov 2023 20:18:26 -0700 Subject: [PATCH] ruff: Fix TRY002 Create your own exception. Signed-off-by: Anders Kaseorg --- zulip/integrations/zephyr/zephyr_mirror_backend.py | 4 ++-- zulip_bots/zulip_bots/bots/xkcd/xkcd.py | 2 +- zulip_bots/zulip_bots/test_lib.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/zulip/integrations/zephyr/zephyr_mirror_backend.py b/zulip/integrations/zephyr/zephyr_mirror_backend.py index 5a96f0da2..43bcd5995 100755 --- a/zulip/integrations/zephyr/zephyr_mirror_backend.py +++ b/zulip/integrations/zephyr/zephyr_mirror_backend.py @@ -73,7 +73,7 @@ def to_zephyr_username(zulip_username: str) -> str: return user.lower() + "@ATHENA.MIT.EDU" match_user = re.match(r"([a-zA-Z0-9_]+)\|(.+)", user) if not match_user: - raise Exception(f"Could not parse Zephyr realm for cross-realm user {zulip_username}") + raise ValueError(f"Could not parse Zephyr realm for cross-realm user {zulip_username}") return match_user.group(1).lower() + "@" + match_user.group(2).upper() @@ -307,7 +307,7 @@ def maybe_restart_mirroring_script() -> None: except Exception: logger.exception("Error restarting mirroring script; trying again... Traceback:") backoff.fail() - raise Exception("Failed to reload too many times, aborting!") + raise RuntimeError("Failed to reload too many times, aborting!") def process_loop(zulip_queue: "Queue[ZephyrDict]", log: Optional[IO[str]]) -> NoReturn: diff --git a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py index 691bd6645..f30bca47e 100644 --- a/zulip_bots/zulip_bots/bots/xkcd/xkcd.py +++ b/zulip_bots/zulip_bots/bots/xkcd/xkcd.py @@ -114,7 +114,7 @@ def fetch_xkcd_query(mode: int, comic_id: Optional[str] = None) -> Dict[str, str elif mode == XkcdBotCommand.COMIC_ID: # Fetch specific comic strip by id number. if comic_id is None: - raise Exception("Missing comic_id argument") + raise TypeError("Missing comic_id argument") url = XKCD_TEMPLATE_URL % (comic_id,) fetched = requests.get(url) diff --git a/zulip_bots/zulip_bots/test_lib.py b/zulip_bots/zulip_bots/test_lib.py index 236f690e4..2d9b98c8c 100644 --- a/zulip_bots/zulip_bots/test_lib.py +++ b/zulip_bots/zulip_bots/test_lib.py @@ -68,9 +68,9 @@ def unique_response(self) -> Dict[str, Any]: def ensure_unique_response(self, responses: List[Dict[str, Any]]) -> None: if not responses: - raise Exception("The bot is not responding for some reason.") + raise ValueError("The bot is not responding for some reason.") if len(responses) > 1: - raise Exception("The bot is giving too many responses for some reason.") + raise ValueError("The bot is giving too many responses for some reason.") class DefaultTests: