Skip to content

Commit 1cb7fdd

Browse files
committed
ruff: Fix TRY301 Abstract raise to an inner function.
Signed-off-by: Anders Kaseorg <[email protected]>
1 parent f26b861 commit 1cb7fdd

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

zulip_bots/zulip_bots/bot_shell.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,8 @@ def main() -> None:
4545
bot_dir = os.path.dirname(bot_path)
4646
sys.path.insert(0, bot_dir)
4747

48-
try:
49-
lib_module = import_module_from_source(bot_path.as_posix(), bot_name)
50-
if lib_module is None:
51-
raise OSError
52-
except OSError:
48+
lib_module = import_module_from_source(bot_path.as_posix(), bot_name)
49+
if lib_module is None:
5350
print(f"Could not find and import bot '{bot_name}'")
5451
sys.exit(1)
5552

zulip_bots/zulip_bots/bots/idonethis/idonethis.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ def __init__(self, team: str) -> None:
2121
self.team = team
2222

2323

24-
class UnknownCommandSyntaxError(Exception):
25-
def __init__(self, detail: str) -> None:
26-
self.detail = detail
27-
28-
2924
class UnspecifiedProblemError(Exception):
3025
pass
3126

@@ -114,6 +109,13 @@ def entries_list(team_name: str) -> str:
114109
return response
115110

116111

112+
def unknown_command_reply(detail: str) -> str:
113+
return (
114+
"Sorry, I don't understand what your trying to say. Use `@mention help` to see my help. "
115+
+ detail
116+
)
117+
118+
117119
def create_entry(message: str) -> str:
118120
single_word_regex = re.compile("--team=([a-zA-Z0-9_]*)")
119121
multiword_regex = re.compile('"--team=([^"]*)"')
@@ -133,7 +135,7 @@ def create_entry(message: str) -> str:
133135
team = default_team
134136
new_message = message
135137
else:
136-
raise UnknownCommandSyntaxError(
138+
return unknown_command_reply(
137139
"""I don't know which team you meant for me to create an entry under.
138140
Either set a default team or pass the `--team` flag.
139141
More information in my help"""
@@ -219,7 +221,7 @@ def get_response(self, message: Dict[str, Any]) -> str:
219221
if len(message_content) > 2:
220222
reply = team_info(" ".join(message_content[2:]))
221223
else:
222-
raise UnknownCommandSyntaxError(
224+
reply = unknown_command_reply(
223225
"You must specify the team in which you request information from."
224226
)
225227
elif command in ["entries list", "list entries"]:
@@ -229,7 +231,7 @@ def get_response(self, message: Dict[str, Any]) -> str:
229231
elif command in ["help"]:
230232
reply = self.usage()
231233
else:
232-
raise UnknownCommandSyntaxError(
234+
reply = unknown_command_reply(
233235
"I can't understand the command you sent me :confused: "
234236
)
235237
except TeamNotFoundError as e:
@@ -239,11 +241,6 @@ def get_response(self, message: Dict[str, Any]) -> str:
239241
except AuthenticationError:
240242
reply = "I can't currently authenticate with idonethis. "
241243
reply += "Can you check that your API key is correct? For more information see my documentation."
242-
except UnknownCommandSyntaxError as e:
243-
reply = (
244-
"Sorry, I don't understand what your trying to say. Use `@mention help` to see my help. "
245-
+ e.detail
246-
)
247244
except Exception: # catches UnspecifiedProblemException, and other problems
248245
reply = "Oh dear, I'm having problems processing your request right now. Perhaps you could try again later :grinning:"
249246
logging.exception("Exception caught")

0 commit comments

Comments
 (0)