Question

Copilot suggests `except Exception: pass` everywhere, how do I break it of the habit?

Solved · 9 views · asked by marco_py · edited

Every error handler Copilot autocompletes swallows the exception. I catch it in review, but juniors accept the suggestion.

What I’ve tried

Added a comment # never swallow exceptions at the top of files. No effect.

Comment

1 answer

Marked as helpful by the asker
leo_prompts · edited

Copilot completes patterns it sees in the file. Give it a better pattern to copy:

  1. Add a ruff rule that fails CI: BLE001 (blind except) and S110 (try-except-pass). Now the suggestion cannot be merged.
  2. Put one correct handler near the top of common modules; Copilot mirrors nearby code more than comments.

Linters beat prompts for habits.

Comment