Logs, Stack Traces & Error Reports
Master the error output and you master debugging.
Stack Traces
Show the path that led to error:
File "main.py", line 15, in <module>
process_user(user_id)
↓
File "service.py", line 42, in process_user
user = get_user(user_id)
↓
File "db.py", line 8, in get_user
return db.query(User).filter(id=user_id).first()
↓
AttributeError: 'NoneType' object has no attribute 'first'Read backwards:
- Last line: The actual error
- Lines above: How you got there
Log Levels
DEBUG: Detailed info for debugging
INFO: General information (startup, etc)
WARNING: Something unexpected, not an error
ERROR: Something failed, but app continues
CRITICAL: App is stoppingUse appropriate level for clarity.
Error Messages
Good error messages have:
❌ Bad:
"Error 404"
✅ Good:
"User with ID 123 not found in database.
Expected user to exist before processing.
Check if user was created successfully."Reporting Errors
When reporting a bug, include:
- Exact error message
- What you did to trigger it
- Expected vs actual behavior
- Stack trace (if available)
- Environment (OS, Python version, etc)
The error message is your best friend. Read it carefully before Googling.