fix: check_self wywala się na starcie, gdy kanał = None #13

Merged
gitea merged 1 commits from fix-check-self-none-channel into main 2026-08-02 17:01:39 +00:00
Owner

Błąd (z logów startowych)

discord.ext.tasks - ERROR - Unhandled exception in internal background task 'check_self'.
  File "/app/administration_commands.py", line 174, in check_self
    messages = [message async for message in channel.history(limit=1)]
AttributeError: 'NoneType' object has no attribute 'history'

Przyczyna

check_self (pętla co 120 s: rollover logów, kompaktowanie pamięci, spontaniczne wiadomości) startuje w setup() podczas on_ready. Jej pierwszy tick potrafi odpalić, zanim gateway zapełni cache kanałówget_channel(1062047367337095268) zwraca Nonechannel.history() rzuca AttributeError. A że nieobsłużony wyjątek w tasks.loop zatrzymuje pętlę, to przy okazji cicho ubijał rollover logów i spontaniczne wiadomości.

Fix

  1. @check_self.before_loopawait self.bot.wait_until_ready() — pierwszy tick czeka aż gateway będzie READY i cache zapełniony (naprawia wyścig startowy).
  2. Guard na None — jeśli kanał i tak jest niedostępny (zły ID / bota nie ma na serwerze / brak uprawnień), tick jest pomijany z ostrzeżeniem, zamiast ubijać całą pętlę.

Niezwiązane z trwałą dostawą wyników (conjurer#12) — osobny, mały fix.

🤖 Generated with Claude Code

## Błąd (z logów startowych) ``` discord.ext.tasks - ERROR - Unhandled exception in internal background task 'check_self'. File "/app/administration_commands.py", line 174, in check_self messages = [message async for message in channel.history(limit=1)] AttributeError: 'NoneType' object has no attribute 'history' ``` ## Przyczyna `check_self` (pętla co 120 s: rollover logów, kompaktowanie pamięci, spontaniczne wiadomości) startuje w `setup()` podczas `on_ready`. Jej **pierwszy tick potrafi odpalić, zanim gateway zapełni cache kanałów** → `get_channel(1062047367337095268)` zwraca `None` → `channel.history()` rzuca `AttributeError`. A że nieobsłużony wyjątek w `tasks.loop` **zatrzymuje pętlę**, to przy okazji **cicho ubijał rollover logów** i spontaniczne wiadomości. ## Fix 1. **`@check_self.before_loop` → `await self.bot.wait_until_ready()`** — pierwszy tick czeka aż gateway będzie READY i cache zapełniony (naprawia wyścig startowy). 2. **Guard na `None`** — jeśli kanał i tak jest niedostępny (zły ID / bota nie ma na serwerze / brak uprawnień), tick jest pomijany z ostrzeżeniem, zamiast ubijać całą pętlę. Niezwiązane z trwałą dostawą wyników (conjurer#12) — osobny, mały fix. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
gitea self-assigned this 2026-08-02 15:37:18 +00:00
gitea added 1 commit 2026-08-02 15:37:18 +00:00
Fix check_self crashing at startup on a None channel
CI / compile (pull_request) Successful in 41s
CI / unit (pull_request) Successful in 20s
CI / integration (pull_request) Successful in 28s
build / build (push) Successful in 41s
CI / compile (push) Successful in 9s
CI / unit (push) Successful in 21s
CI / integration (push) Successful in 25s
8ac68df1c9
check_self starts in setup() (during on_ready), and its first tick can
fire before the gateway has populated the channel cache - get_channel()
then returns None and channel.history() raises AttributeError. Because an
unhandled exception stops a tasks.loop, this also silently killed the log
rollover and spontaneous messages the loop is responsible for.

Add a before_loop that awaits wait_until_ready() (fixes the startup race)
and a None guard that skips the tick with a warning (keeps the loop alive
even if the channel is genuinely unreachable: wrong id / not in the guild
/ missing permission).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
gitea merged commit 8ac68df1c9 into main 2026-08-02 17:01:39 +00:00
gitea deleted branch fix-check-self-none-channel 2026-08-02 17:01:40 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: gitea/conjurer#13