ruff: Fix TRY301 Abstract raise
to an inner function.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
parent
f26b861f51
commit
1cb7fdd5b3
2 changed files with 12 additions and 18 deletions
|
@ -45,11 +45,8 @@ def main() -> None:
|
||||||
bot_dir = os.path.dirname(bot_path)
|
bot_dir = os.path.dirname(bot_path)
|
||||||
sys.path.insert(0, bot_dir)
|
sys.path.insert(0, bot_dir)
|
||||||
|
|
||||||
try:
|
lib_module = import_module_from_source(bot_path.as_posix(), bot_name)
|
||||||
lib_module = import_module_from_source(bot_path.as_posix(), bot_name)
|
if lib_module is None:
|
||||||
if lib_module is None:
|
|
||||||
raise OSError
|
|
||||||
except OSError:
|
|
||||||
print(f"Could not find and import bot '{bot_name}'")
|
print(f"Could not find and import bot '{bot_name}'")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
|
@ -21,11 +21,6 @@ class TeamNotFoundError(Exception):
|
||||||
self.team = team
|
self.team = team
|
||||||
|
|
||||||
|
|
||||||
class UnknownCommandSyntaxError(Exception):
|
|
||||||
def __init__(self, detail: str) -> None:
|
|
||||||
self.detail = detail
|
|
||||||
|
|
||||||
|
|
||||||
class UnspecifiedProblemError(Exception):
|
class UnspecifiedProblemError(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -114,6 +109,13 @@ def entries_list(team_name: str) -> str:
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
def unknown_command_reply(detail: str) -> str:
|
||||||
|
return (
|
||||||
|
"Sorry, I don't understand what your trying to say. Use `@mention help` to see my help. "
|
||||||
|
+ detail
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_entry(message: str) -> str:
|
def create_entry(message: str) -> str:
|
||||||
single_word_regex = re.compile("--team=([a-zA-Z0-9_]*)")
|
single_word_regex = re.compile("--team=([a-zA-Z0-9_]*)")
|
||||||
multiword_regex = re.compile('"--team=([^"]*)"')
|
multiword_regex = re.compile('"--team=([^"]*)"')
|
||||||
|
@ -133,7 +135,7 @@ def create_entry(message: str) -> str:
|
||||||
team = default_team
|
team = default_team
|
||||||
new_message = message
|
new_message = message
|
||||||
else:
|
else:
|
||||||
raise UnknownCommandSyntaxError(
|
return unknown_command_reply(
|
||||||
"""I don't know which team you meant for me to create an entry under.
|
"""I don't know which team you meant for me to create an entry under.
|
||||||
Either set a default team or pass the `--team` flag.
|
Either set a default team or pass the `--team` flag.
|
||||||
More information in my help"""
|
More information in my help"""
|
||||||
|
@ -219,7 +221,7 @@ Below are some of the commands you can use, and what they do.
|
||||||
if len(message_content) > 2:
|
if len(message_content) > 2:
|
||||||
reply = team_info(" ".join(message_content[2:]))
|
reply = team_info(" ".join(message_content[2:]))
|
||||||
else:
|
else:
|
||||||
raise UnknownCommandSyntaxError(
|
reply = unknown_command_reply(
|
||||||
"You must specify the team in which you request information from."
|
"You must specify the team in which you request information from."
|
||||||
)
|
)
|
||||||
elif command in ["entries list", "list entries"]:
|
elif command in ["entries list", "list entries"]:
|
||||||
|
@ -229,7 +231,7 @@ Below are some of the commands you can use, and what they do.
|
||||||
elif command in ["help"]:
|
elif command in ["help"]:
|
||||||
reply = self.usage()
|
reply = self.usage()
|
||||||
else:
|
else:
|
||||||
raise UnknownCommandSyntaxError(
|
reply = unknown_command_reply(
|
||||||
"I can't understand the command you sent me :confused: "
|
"I can't understand the command you sent me :confused: "
|
||||||
)
|
)
|
||||||
except TeamNotFoundError as e:
|
except TeamNotFoundError as e:
|
||||||
|
@ -239,11 +241,6 @@ Below are some of the commands you can use, and what they do.
|
||||||
except AuthenticationError:
|
except AuthenticationError:
|
||||||
reply = "I can't currently authenticate with idonethis. "
|
reply = "I can't currently authenticate with idonethis. "
|
||||||
reply += "Can you check that your API key is correct? For more information see my documentation."
|
reply += "Can you check that your API key is correct? For more information see my documentation."
|
||||||
except UnknownCommandSyntaxError as e:
|
|
||||||
reply = (
|
|
||||||
"Sorry, I don't understand what your trying to say. Use `@mention help` to see my help. "
|
|
||||||
+ e.detail
|
|
||||||
)
|
|
||||||
except Exception: # catches UnspecifiedProblemException, and other problems
|
except Exception: # catches UnspecifiedProblemException, and other problems
|
||||||
reply = "Oh dear, I'm having problems processing your request right now. Perhaps you could try again later :grinning:"
|
reply = "Oh dear, I'm having problems processing your request right now. Perhaps you could try again later :grinning:"
|
||||||
logging.exception("Exception caught")
|
logging.exception("Exception caught")
|
||||||
|
|
Loading…
Add table
Reference in a new issue