Fix bot not going online: stop silently swallowing presence errors

_set_presence was catching all exceptions and logging them at DEBUG
level, which meant connection failures (bad token, unreachable
homeserver, etc.) were completely hidden at the default INFO log level.
The bot would appear to start normally but never actually go online.

Now the initial presence call in start_presence() propagates errors so
startup fails visibly if the Matrix connection doesn't work. The
background heartbeat loop still catches errors but logs them at WARNING.

https://claude.ai/code/session_019ANRdyL2jfi7ysWhqN4PfD
This commit is contained in:
Claude
2026-02-28 09:04:28 +00:00
parent 6812758af0
commit 8d7a66c431

View File

@@ -38,23 +38,26 @@ async def close_client() -> None:
pass
_presence_task = None
if _client is not None:
await _set_presence("offline")
try:
await _set_presence("offline")
except Exception:
log.warning("Failed to set offline presence during shutdown", exc_info=True)
await _client.close()
_client = None
async def _set_presence(state: str) -> None:
client = await get_client()
try:
await client.set_presence(state)
except Exception:
log.debug("Presence update failed", exc_info=True)
await client.set_presence(state)
async def _presence_loop() -> None:
while True:
await _set_presence("online")
await asyncio.sleep(PRESENCE_INTERVAL_SECONDS)
try:
await _set_presence("online")
except Exception:
log.warning("Presence heartbeat failed", exc_info=True)
async def start_presence() -> None: