Skip to content

docs(guidelines): add exception handling section to backend Python guide#9804

Merged
saltas888 merged 2 commits into
developfrom
feat/suspicious-jemison-d914b9
Jul 6, 2026
Merged

docs(guidelines): add exception handling section to backend Python guide#9804
saltas888 merged 2 commits into
developfrom
feat/suspicious-jemison-d914b9

Conversation

@saltas888

@saltas888 saltas888 commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Why

The backend Python guidelines had no guidance on exception handling, so broad except Exception / bare except: patterns that swallow programming errors and silence real failures had nothing to point reviewers at.

What changed

  • Added an Exception Handling section to dev/guidelines/backend/python.md covering: catch only expected exceptions, name the narrowest type(s), keep the try body small, never silence, and re-raise what you can't handle.
  • Included good/bad examples and the one justified case for a broad catch (top-level boundary that logs and re-raises).

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.md to 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.

Review in cubic

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@saltas888 saltas888 requested a review from a team as a code owner July 3, 2026 14:37
@saltas888 saltas888 added type/documentation Improvements or additions to documentation group/backend Issue related to the backend (API Server, Git Agent) labels Jul 3, 2026
@github-actions github-actions Bot removed type/documentation Improvements or additions to documentation group/backend Issue related to the backend (API Server, Git Agent) labels Jul 3, 2026

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 1 file

Confidence score: 5/5

  • In dev/guidelines/backend/python.md, the exception-handling guidance is slightly inaccurate about except Exception vs bare except:, 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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 dgarros left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@saltas888 saltas888 merged commit 818bbaf into develop Jul 6, 2026
43 checks passed
@saltas888 saltas888 deleted the feat/suspicious-jemison-d914b9 branch July 6, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants