mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 13:34:40 +00:00
fix: never swallow task exceptions - diagnose WHY the bot died
The restart-loop with only 'Starting discord bot' in the logs was caused by
gather(return_exceptions=True) eating the client.start() exception: a failed
login looked like a clean exit and docker just restarted the container.
bot.py:
- _run_bot: catch discord.LoginFailure / PrivilegedIntentsRequired with
CRITICAL messages telling exactly what to fix (token entry / Developer
Portal intents), full traceback for anything else, then re-raise
- main() returns an exit code; every task exception is re-logged as the
LAST line in docker logs ('Task died: ...'); process exits 1 on failure
- log the token source (env vs netrc) and its length at startup to catch
truncated/wrong-field netrc entries
- _run_comm_subroutine: comm crash is logged loudly but no longer relies on
gather to surface it (bot keeps running - Discord side is independent)
communication_subroutine.py (crash found by the new stub tests):
- comm_subroutine used 'logger' before its local assignment
(UnboundLocalError killed the whole comm layer at every startup)
- re-comment the flask_debug thread: it binds the same host:port as
waitress, so running both dies with 'address in use'
Verified via stub-injected client: LoginFailure -> CRITICAL + exit 1,
PrivilegedIntentsRequired -> CRITICAL + exit 1, unknown exception -> full
traceback + exit 1, clean shutdown -> exit 0; comm layer no longer crashes.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -234,11 +234,14 @@ def comm_subroutine(stop_event: Optional[threading.Event] = None):
|
||||
:param stop_event: optional :class:`threading.Event` shared with the caller
|
||||
to coordinate a cooperative shutdown.
|
||||
"""
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger = logging.getLogger("discord")
|
||||
logger.setLevel(logging.DEBUG)
|
||||
logger.info("Started comms")
|
||||
threads = []
|
||||
threads.append(threading.Thread(target=flask_debug))
|
||||
# NOTE: flask_debug is the dev server bound to the SAME host:port as
|
||||
# waitress - running both kills the comm layer with 'address in use'.
|
||||
# Enable it only INSTEAD of waitress_run, never alongside.
|
||||
# threads.append(threading.Thread(target=flask_debug))
|
||||
threads.append(threading.Thread(target=waitress_run, daemon=True))
|
||||
threads.append(
|
||||
threading.Thread(
|
||||
|
||||
Reference in New Issue
Block a user