Exit code handling (#3360)

* Exit code handling

* clear up a docstring
This commit is contained in:
Michael H 2020-01-13 11:37:49 -05:00 committed by GitHub
parent ef8b57a1d2
commit a7987a83fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -288,7 +288,18 @@ def handle_edit(cli_flags: Namespace):
sys.exit(0)
async def run_bot(red: Red, cli_flags: Namespace) -> NoReturn:
async def run_bot(red: Red, cli_flags: Namespace) -> None:
"""
This runs the bot.
Any shutdown which is a result of not being able to log in needs to raise
a SystemExit exception.
If the bot starts normally, the bot should be left to handle the exit case.
It will raise SystemExit in a task, which will reach the event loop and
interrupt running forever, then trigger our cleanup process, and does not
need additional handling in this function.
"""
driver_cls = drivers.get_driver_class()
@ -335,7 +346,6 @@ async def run_bot(red: Red, cli_flags: Namespace) -> NoReturn:
sys.exit(0)
try:
await red.start(token, bot=True, cli_flags=cli_flags)
# This raises SystemExit in normal use at close
except discord.LoginFailure:
log.critical("This token doesn't seem to be valid.")
db_token = await red._config.token()
@ -346,6 +356,8 @@ async def run_bot(red: Red, cli_flags: Namespace) -> NoReturn:
sys.exit(0)
sys.exit(1)
return None
def handle_early_exit_flags(cli_flags: Namespace):
if cli_flags.list_instances: