Skip to content

fix: potential UnboundLocalError in handle_document handler #63

@RinZ27

Description

@RinZ27

Describe the bug
A potential UnboundLocalError exists in the handle_document function within src/bot/handlers/message.py. If an exception occurs during file processing (e.g., after the progress message is sent but before the prompt variable is assigned), the subsequent call to claude_integration.run_command(prompt=prompt, ...) will fail because prompt has not been initialized.

To Reproduce

  1. Send a document that causes an exception during processing (other than UnicodeDecodeError).
  2. The code attempts to use the prompt variable in the try...except block starting at line 552.
  3. The bot crashes with UnboundLocalError: local variable 'prompt' referenced before assignment.

Expected behavior
The prompt variable should be initialized with a default value or the function should return early if processing fails, preventing a crash.

Environment

  • OS: [e.g. macOS, Linux]
  • Python version: 3.9+
  • Project Version: v1.0.1

Additional context
I noticed this while auditing the message handling logic. Initializing the variable at the top of the handler or ensuring it's always set before use would resolve this. I'll be submitting a PR to address this shortly.

I'm also looking into adding more specific logging to the empty except: pass blocks in the same file to improve observability as requested in the development guidelines.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions