fix: preserve original exception context in retry decorator#8832
fix: preserve original exception context in retry decorator#8832dreamcreated wants to merge 1 commit intoaws:developfrom
Conversation
When all retry attempts are exhausted, the decorator previously raised exc_raise(exc_raise_msg) without chaining the original exception, making it impossible to diagnose the root cause from the traceback. Fix: capture the last caught exception and chain it using 'raise ... from last_exception' so Python's exception chaining (__cause__) is preserved in the traceback. Fixes: bnusunny#29
|
@dreamcreated Thank you for raising this! You said "Fixes #29" but I think that may be a typo, what issue does this fix? Just so we can link it properly |
|
Hi @seshubaws, thank you for pointing that out! Yes, that was a typo — the original issue report is in the fork at bnusunny#29 (a good-first-issue tracking the same problem). The upstream The core problem: the Happy to open a dedicated tracking issue on |
Problem
The
retrydecorator insamcli/lib/utils/retry.pyswallows the original exception when all retries are exhausted. This makes it impossible to diagnose the root cause of failures because the original traceback is lost.Before this fix:
Fix
Capture the last exception and chain it using
raise ... from last_exception:This preserves the original traceback via Python exception chaining (
__cause__), making it much easier to diagnose the root cause of failures.Testing
The change is backwards-compatible — the raised exception type and message remain the same, only the
__cause__is now populated.Related