From 235f92afb0f0eacbc7165d780baed89731fc9fe1 Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Sat, 28 Oct 2023 16:27:48 -0700 Subject: [PATCH] ruff: Fix TRY401 Redundant exception object included in `logging.exception` call. Signed-off-by: Anders Kaseorg --- zulip_bots/zulip_bots/bots/beeminder/beeminder.py | 8 ++++---- zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py | 2 +- zulip_bots/zulip_bots/bots/flock/flock.py | 4 ++-- zulip_bots/zulip_bots/bots/github_detail/github_detail.py | 4 ++-- zulip_bots/zulip_bots/bots/google_search/google_search.py | 2 +- zulip_bots/zulip_bots/game_handler.py | 2 +- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/zulip_bots/zulip_bots/bots/beeminder/beeminder.py b/zulip_bots/zulip_bots/bots/beeminder/beeminder.py index a0be21ae..87657439 100644 --- a/zulip_bots/zulip_bots/bots/beeminder/beeminder.py +++ b/zulip_bots/zulip_bots/bots/beeminder/beeminder.py @@ -70,8 +70,8 @@ at syntax by: @mention-botname help" return ( f"[Datapoint]({datapoint_link}) created." ) # Handles the case of successful datapoint creation - except ConnectionError as e: - logging.exception(str(e)) + except ConnectionError: + logging.exception("Error connecting to Beeminder") return "Uh-Oh, couldn't process the request \ right now.\nPlease try again later" @@ -92,8 +92,8 @@ class BeeminderHandler: ) if r.status_code == 401: bot_handler.quit("Invalid key!") - except ConnectionError as e: - logging.exception(str(e)) + except ConnectionError: + logging.exception("Error connecting to Beeminder") def usage(self) -> str: return "This plugin allows users to add datapoints towards their Beeminder goals" diff --git a/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py b/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py index 16ea544d..d2f705fc 100644 --- a/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py +++ b/zulip_bots/zulip_bots/bots/dialogflow/dialogflow.py @@ -35,7 +35,7 @@ def get_bot_result(message_content: str, config: Dict[str, str], sender_id: str) return "Error. No result." return res_json["result"]["fulfillment"]["speech"] except Exception as e: - logging.exception(str(e)) + logging.exception("Error getting Dialogflow bot response") return f"Error. {e}." diff --git a/zulip_bots/zulip_bots/bots/flock/flock.py b/zulip_bots/zulip_bots/bots/flock/flock.py index 918f4b34..8dbd15f8 100644 --- a/zulip_bots/zulip_bots/bots/flock/flock.py +++ b/zulip_bots/zulip_bots/bots/flock/flock.py @@ -30,8 +30,8 @@ def make_flock_request(url: str, params: Dict[str, str]) -> Tuple[Any, str]: try: res = requests.get(url, params=params) return (res.json(), None) - except ConnectionError as e: - logging.exception(str(e)) + except ConnectionError: + logging.exception("Error connecting to Flock") error = "Uh-Oh, couldn't process the request \ right now.\nPlease try again later" return (None, error) diff --git a/zulip_bots/zulip_bots/bots/github_detail/github_detail.py b/zulip_bots/zulip_bots/bots/github_detail/github_detail.py index 071094ff..865756ac 100644 --- a/zulip_bots/zulip_bots/bots/github_detail/github_detail.py +++ b/zulip_bots/zulip_bots/bots/github_detail/github_detail.py @@ -57,8 +57,8 @@ class GithubHandler: r = requests.get( self.GITHUB_ISSUE_URL_TEMPLATE.format(owner=owner, repo=repo, id=number) ) - except requests.exceptions.RequestException as e: - logging.exception(str(e)) + except requests.exceptions.RequestException: + logging.exception("Error connecting to GitHub") return None if r.status_code != requests.codes.ok: return None diff --git a/zulip_bots/zulip_bots/bots/google_search/google_search.py b/zulip_bots/zulip_bots/bots/google_search/google_search.py index 007ffc02..758157e4 100644 --- a/zulip_bots/zulip_bots/bots/google_search/google_search.py +++ b/zulip_bots/zulip_bots/bots/google_search/google_search.py @@ -62,7 +62,7 @@ def get_google_result(search_keywords: str) -> str: return "Found no results." return "Found Result: [{}]({})".format(results[0]["name"], results[0]["url"]) except Exception as e: - logging.exception(str(e)) + logging.exception("Error fetching Google results") return f"Error: Search failed. {e}." diff --git a/zulip_bots/zulip_bots/game_handler.py b/zulip_bots/zulip_bots/game_handler.py index f46a7238..c00a1407 100644 --- a/zulip_bots/zulip_bots/game_handler.py +++ b/zulip_bots/zulip_bots/game_handler.py @@ -296,7 +296,7 @@ class GameAdapter: else: self.send_reply(message, self.help_message()) except Exception as e: - logging.exception(str(e)) + logging.exception("Error handling game message") self.bot_handler.send_reply(message, f"Error {e}.") def is_user_in_game(self, user_email: str) -> str: