Skip to content

fix: preserve original exception context in retry decorator#63

Open
armorbreak001 wants to merge 1 commit into
bnusunny:developfrom
armorbreak001:fix/retry-exception-context
Open

fix: preserve original exception context in retry decorator#63
armorbreak001 wants to merge 1 commit into
bnusunny:developfrom
armorbreak001:fix/retry-exception-context

Conversation

@armorbreak001

Copy link
Copy Markdown

Summary

Fixes #29

The retry decorator in samcli/lib/utils/retry.py now preserves the original exception context when all retries are exhausted.

Before: raise exc_raise(exc_raise_msg) — original exception was completely lost, making debugging impossible.

After: raise exc_raise(exc_raise_msg) from last_exc — Python exception chaining preserves the full traceback and original error message.

Changes

  • Store each caught exception in last_exc
  • Also break out of the retry loop for non-target exception types (avoid infinite loop on unexpected exceptions)
  • Use raise ... from last_exc for proper exception chaining

Test

@retry(ValueError, attempts=2)
def flaky():
    raise ValueError("original error")
# Now shows: Exception: retry failed
# The above exception was the direct cause of: ValueError: original error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: retry decorator swallows original exception context

1 participant