docs(guidelines): add exception handling section to backend Python guide#9804
Merged
Conversation
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
1 issue found across 1 file
Confidence score: 5/5
- In
dev/guidelines/backend/python.md, the exception-handling guidance is slightly inaccurate aboutexcept Exceptionvs bareexcept:, which could mislead readers into over-restrictive or incorrect style choices; this is documentation-only and low runtime risk, but update the sentence before merging to prevent future confusion.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="dev/guidelines/backend/python.md">
<violation number="1" location="dev/guidelines/backend/python.md:283">
P3: This guideline sentence currently implies that both bare `except:` and `except Exception` swallow `KeyboardInterrupt`/`SystemExit`, but in Python only bare `except:` (or `except BaseException`) does that. Clarifying this distinction would keep the new section accurate and avoid reviewers rejecting `except Exception` for the wrong reason.</violation>
</file>
Shadow auto-approve: would not auto-approve because issues were found.
Re-trigger cubic
|
|
||
| ## Exception Handling | ||
|
|
||
| Catch only the exceptions you expect and know how to handle. Do not use bare `except:` or a broad `except Exception` to wrap code you haven't verified can raise something you can recover from — it swallows `KeyboardInterrupt`/`SystemExit` intent, hides bugs (typos, `AttributeError`, misconfiguration) behind the same handler as the error you meant to catch, and makes failures silent. |
Contributor
There was a problem hiding this comment.
P3: This guideline sentence currently implies that both bare except: and except Exception swallow KeyboardInterrupt/SystemExit, but in Python only bare except: (or except BaseException) does that. Clarifying this distinction would keep the new section accurate and avoid reviewers rejecting except Exception for the wrong reason.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At dev/guidelines/backend/python.md, line 283:
<comment>This guideline sentence currently implies that both bare `except:` and `except Exception` swallow `KeyboardInterrupt`/`SystemExit`, but in Python only bare `except:` (or `except BaseException`) does that. Clarifying this distinction would keep the new section accurate and avoid reviewers rejecting `except Exception` for the wrong reason.</comment>
<file context>
@@ -278,6 +278,42 @@ Exceptions where positional arguments are acceptable:
+## Exception Handling
+
+Catch only the exceptions you expect and know how to handle. Do not use bare `except:` or a broad `except Exception` to wrap code you haven't verified can raise something you can recover from — it swallows `KeyboardInterrupt`/`SystemExit` intent, hides bugs (typos, `AttributeError`, misconfiguration) behind the same handler as the error you meant to catch, and makes failures silent.
+
+```python
</file context>
Suggested change
| Catch only the exceptions you expect and know how to handle. Do not use bare `except:` or a broad `except Exception` to wrap code you haven't verified can raise something you can recover from — it swallows `KeyboardInterrupt`/`SystemExit` intent, hides bugs (typos, `AttributeError`, misconfiguration) behind the same handler as the error you meant to catch, and makes failures silent. | |
| Catch only the exceptions you expect and know how to handle. Do not use bare `except:` or broad `except Exception` to wrap code you haven't verified can raise something you can recover from: bare `except:` also catches `KeyboardInterrupt`/`SystemExit`, while `except Exception` can still hide programming bugs (typos, `AttributeError`, misconfiguration) behind the same handler as the error you meant to catch and make failures harder to diagnose. |
dgarros
approved these changes
Jul 3, 2026
dgarros
left a comment
Collaborator
There was a problem hiding this comment.
Looks good, recently we also started using rules in .agents/rules, I could see this one being a rule as well
I think either way works
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The backend Python guidelines had no guidance on exception handling, so broad
except Exception/ bareexcept:patterns that swallow programming errors and silence real failures had nothing to point reviewers at.What changed
dev/guidelines/backend/python.mdcovering: catch only expected exceptions, name the narrowest type(s), keep thetrybody small, never silence, and re-raise what you can't handle.Docs-only change — no code, no behavior change.
How to review
Read the new section in
dev/guidelines/backend/python.md.Summary by cubic
Add an Exception Handling section to
dev/guidelines/backend/python.mdto discourage broad catches that hide real failures and set clear review standards. It covers catching only expected exceptions, naming narrow types, keeping try blocks small, never silencing errors, re-raising when unhandled, and includes good/bad examples plus the single justified broad-catch case at top-level boundaries.Written for commit 4f92d02. Summary will update on new commits.