Skip to content
Sarj Code Standards

prefer-exception-propagation

Propagate exceptions instead of replacing them with message-only generic errors.

Why

Catching an exception only to copy its text into a generic error loses the original error type and adds a handler without recovery or additional context. Callers then cannot classify the original failure.

Fix

Remove the message-only handler and let the original exception propagate. Preserve intentional public exception contracts, privacy, retries and cleanup. Keep an explained exact-code exception when the generic exception type is an intentional boundary contract.

Examples

Before — flagged A generic CLI replacement hides the original failure
app/send.py
try:
send()
except (OSError, ValueError):
message = "Request failed"
raise SystemExit(message) from None
After — preferred The original failure retains its type and context
app/send.py
send()
Before — flagged The wrapper only copies the original message
app/send.py
try:
send()
except Exception as error:
raise RuntimeError(str(error)) from error
After — preferred Let the original exception reach its owner
app/send.py
send()