CRITICAL: BOT_USER None Reference Causes Crashes #20

Open
opened 2026-02-16 22:40:19 +02:00 by Koko210 · 0 comments
Owner

globals.BOT_USER is accessed without null checks, causing AttributeError when it is None.

Where It Occurs

  • bot/globals.py - BOT_USER variable definition
  • bot/utils/moods.py - Direct access to BOT_USER without check
  • Various files assuming BOT_USER is always set

Why This Is a Problem

  1. Crashes: AttributeError when accessing None object
  2. Race Condition: BOT_USER may not be set when event handlers fire
  3. Silent Failures: Background tasks crash without logging
  4. Unpredictable: Bot works until specific event triggers crash

What Can Go Wrong

Scenario 1: Early Event Handler

  1. Bot connects to Discord
  2. on_ready event fires before BOT_USER is set
  3. Event handler tries to access BOT_USER.name
  4. BOT_USER is None, raises AttributeError
  5. Bot crashes immediately on startup

Scenario 2: Mood System Crash

  1. User sends message to change mood
  2. Mood system tries to access globals.BOT_USER.display_name
  3. BOT_USER is None (race condition during initialization)
  4. AttributeError raised
  5. Mood change fails, bot continues but feature broken

Proposed Fix

Add null checks and initialize with safe default. Create get_bot_user() helper that raises RuntimeError if not initialized.

Severity

CRITICAL - None references cause immediate crashes on startup and during operation.

Files Affected

bot/globals.py, bot/utils/moods.py

globals.BOT_USER is accessed without null checks, causing AttributeError when it is None. ## Where It Occurs - bot/globals.py - BOT_USER variable definition - bot/utils/moods.py - Direct access to BOT_USER without check - Various files assuming BOT_USER is always set ## Why This Is a Problem 1. Crashes: AttributeError when accessing None object 2. Race Condition: BOT_USER may not be set when event handlers fire 3. Silent Failures: Background tasks crash without logging 4. Unpredictable: Bot works until specific event triggers crash ## What Can Go Wrong ### Scenario 1: Early Event Handler 1. Bot connects to Discord 2. on_ready event fires before BOT_USER is set 3. Event handler tries to access BOT_USER.name 4. BOT_USER is None, raises AttributeError 5. Bot crashes immediately on startup ### Scenario 2: Mood System Crash 1. User sends message to change mood 2. Mood system tries to access globals.BOT_USER.display_name 3. BOT_USER is None (race condition during initialization) 4. AttributeError raised 5. Mood change fails, bot continues but feature broken ## Proposed Fix Add null checks and initialize with safe default. Create get_bot_user() helper that raises RuntimeError if not initialized. ## Severity CRITICAL - None references cause immediate crashes on startup and during operation. ## Files Affected bot/globals.py, bot/utils/moods.py
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Koko210/miku-discord#20