-
Notifications
You must be signed in to change notification settings - Fork 312
fix: potential UnboundLocalError in handle_document handler #63
Description
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
- Send a document that causes an exception during processing (other than
UnicodeDecodeError). - The code attempts to use the
promptvariable in thetry...exceptblock starting at line 552. - 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.