When handling errors, ensure (1) you don’t accidentally change which exception path fires, (2) recovery/cleanup is deterministic, and (3) any wrapping/aggregation preserves context and remains actionable.
Practical rules:
Example (retryable vs aggregated failures + chaining):
exceptions = []
for item in items:
try:
do_bind(item)
except Exception as e:
if isinstance(e, RETRIED_EXCEPTIONS):
raise # preserve intended retry/outer mechanism
exceptions.append(e)
if exceptions:
raise RuntimeError(
"Binding failures occurred\n" + "\n".join(map(str, exceptions))
)
# During failure-path cleanup:
try:
hub.reset()
except Exception:
pass
try:
hub.timer.clear() # must still run
except Exception:
pass
Apply this standard whenever you touch error recovery, retry/fallback behavior, exception aggregation/wrapping, or shutdown/reconnect paths.
Enter the URL of a public GitHub repository