Python Error Handling
Priority: P1 (HIGH)
Rules
- Catch the narrowest exception you can explain.
- Roll back mutable state before re-raising or returning failure status.
- Add context to logs and raised errors without discarding the root cause.
- Preserve blocker truth; do not convert real failure into vague success text.
Recipe
- Handle expected failures close to the boundary.
- Re-raise unexpected failures after cleanup.
- Return structured blocker or verdict data when the caller needs workflow truth.
- Test timeout, malformed input, and missing-env paths.
Anti-Patterns
- No silent
except Exception: pass. - No broad catch that marks work complete without evidence.
- No duplicate logging at every stack layer.
- No blocker text without owner or next action when the protocol needs both.