Title: fix: preserve exception cause by fercor-cisco · Pull Request #879 · googleapis/python-api-core · GitHub
Open Graph Title: fix: preserve exception cause by fercor-cisco · Pull Request #879 · googleapis/python-api-core
X Title: fix: preserve exception cause by fercor-cisco · Pull Request #879 · googleapis/python-api-core
Description: Fixes #880
Problem:
When the retry mechanism re-raises non-retryable exceptions, it explicitly clears the exception chain by using raise final_exc from None. This breaks explicit exception chaining created with raise ... from ..., making the original cause (cause) inaccessible for debugging.
Fix:
Modified _default_exception_factory() in retry_base.py to preserve the __cause__ attribute when re-raising non-retryable exceptions. Instead of returning (exc_list[-1], None), we now return (exc_list[-1], getattr(exc_list[-1], '__cause__', None)).
This ensures that exception chains are maintained through the retry mechanism, preserving debugging information and meeting developer expectations for exception handling.
Testing:
Added a new test case in tests/unit/retry/test_retry_base.py that checks that the cause from the chained exception is preserved by build_retry_error.
Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:
Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
Ensure the tests and linter pass
Code coverage does not decrease (if any source code was changed)
Appropriate docs were updated (if necessary)
Fixes #
Open Graph Description: Fixes #880 Problem: When the retry mechanism re-raises non-retryable exceptions, it explicitly clears the exception chain by using raise final_exc from None. This breaks explicit exception chaining...
X Description: Fixes #880 Problem: When the retry mechanism re-raises non-retryable exceptions, it explicitly clears the exception chain by using raise final_exc from None. This breaks explicit exception chaining...
Opengraph URL: https://github.com/googleapis/python-api-core/pull/879
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:9c176aaf-fa26-7d90-dcd2-6f99ad168357 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 9970:33E8BE:1577B11:1F3A90A:6A4E46F0 |
| html-safe-nonce | 6a193bd874b35c8413097b6163e8ea953f607b57646113403b5e1afd8865b369 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OTcwOjMzRThCRToxNTc3QjExOjFGM0E5MEE6NkE0RTQ2RjAiLCJ2aXNpdG9yX2lkIjoiMjgxNTc5NTQ0MzEwMjc5NTUwNCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 1eb913c907a60e45ad847cfb85bb5b7cbe607b3aafb85a2bc8b2df0182ed365d |
| hovercard-subject-tag | pull_request:3119222080 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/googleapis/python-api-core/pull/879/files |
| twitter:image | https://avatars.githubusercontent.com/u/241859342?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/241859342?s=400&v=4 |
| og:image:alt | Fixes #880 Problem: When the retry mechanism re-raises non-retryable exceptions, it explicitly clears the exception chain by using raise final_exc from None. This breaks explicit exception chaining... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 030096ee0db095447bfe77409d33bfac127ca7128299c58deef27c52eaa1b1f0 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/googleapis/python-api-core git https://github.com/googleapis/python-api-core.git |
| octolytics-dimension-user_id | 16785467 |
| octolytics-dimension-user_login | googleapis |
| octolytics-dimension-repository_id | 226992456 |
| octolytics-dimension-repository_nwo | googleapis/python-api-core |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 226992456 |
| octolytics-dimension-repository_network_root_nwo | googleapis/python-api-core |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9fabff9b8b127e686a3ec86f91422e818056ca2c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width