ruff: Fix TRY002 Create your own exception.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-11-01 20:18:26 -07:00
parent 751b4716c8
commit a2ddac75f3
3 changed files with 5 additions and 5 deletions

View file

@ -73,7 +73,7 @@ def to_zephyr_username(zulip_username: str) -> str:
return user.lower() + "@ATHENA.MIT.EDU" return user.lower() + "@ATHENA.MIT.EDU"
match_user = re.match(r"([a-zA-Z0-9_]+)\|(.+)", user) match_user = re.match(r"([a-zA-Z0-9_]+)\|(.+)", user)
if not match_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() return match_user.group(1).lower() + "@" + match_user.group(2).upper()
@ -307,7 +307,7 @@ def maybe_restart_mirroring_script() -> None:
except Exception: except Exception:
logger.exception("Error restarting mirroring script; trying again... Traceback:") logger.exception("Error restarting mirroring script; trying again... Traceback:")
backoff.fail() 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: def process_loop(zulip_queue: "Queue[ZephyrDict]", log: Optional[IO[str]]) -> NoReturn:

View file

@ -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. elif mode == XkcdBotCommand.COMIC_ID: # Fetch specific comic strip by id number.
if comic_id is None: if comic_id is None:
raise Exception("Missing comic_id argument") raise TypeError("Missing comic_id argument")
url = XKCD_TEMPLATE_URL % (comic_id,) url = XKCD_TEMPLATE_URL % (comic_id,)
fetched = requests.get(url) fetched = requests.get(url)

View file

@ -68,9 +68,9 @@ class StubBotHandler:
def ensure_unique_response(self, responses: List[Dict[str, Any]]) -> None: def ensure_unique_response(self, responses: List[Dict[str, Any]]) -> None:
if not responses: 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: 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: class DefaultTests: