fix: call post_init_error within init exception handling block - #217
Open
rudraroop wants to merge 1 commit into
Open
fix: call post_init_error within init exception handling block#217rudraroop wants to merge 1 commit into
rudraroop wants to merge 1 commit into
Conversation
Restores sys.exc_info() access for tools that monkey-patch post_init_error (e.g. Sentry SDK). The init error paths are merged into a single except block that type-checks FaultException, keeping error reporting behavior identical for both paths. Fixes #172
There was a problem hiding this comment.
Pull request overview
This PR restores access to the active init exception (sys.exc_info()) for integrations that monkey-patch post_init_error (e.g., Sentry), by ensuring post_init_error is invoked while the init exception is still being handled in bootstrap.run().
Changes:
- Merge the init-time
except FaultExceptionandexcept Exceptionpaths into a singleexcept Exceptionblock that preserves priorerror_resultconstruction behavior. - Move
post_init_error(error_result)andsys.exit(1)inside theexceptblock sosys.exc_info()remains populated. - Add regression tests that assert
sys.exc_info()is non-empty inside a mockedpost_init_errorfor both FaultException and generic-exception init failures.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
awslambdaric/bootstrap.py |
Calls post_init_error within the init exception handler and preserves prior FaultException vs generic exception error shaping. |
tests/test_bootstrap.py |
Adds regression tests verifying sys.exc_info() is available inside post_init_error for both init error paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Restores sys.exc_info() access for tools that monkey-patch post_init_error (e.g. Sentry SDK). The init error paths are merged into a single except block that type-checks FaultException, keeping error reporting behavior identical for both paths.
Fixes #172
Description of changes:
PR #163 moved the
post_init_errorcall inbootstrap.run()outside theexceptblocks. Since Python clears the handled exception once anexceptblock exits,sys.exc_info()returns(None, None, None)by the timepost_init_errorruns. This broke APM tools such as the Sentry SDK, which monkey-patchpost_init_errorand rely onsys.exc_info()to capture init errors (see #172).An earlier community fix (#171) was closed because it moved the call under only one of the two
exceptclauses, which would have dropped error reporting for theFaultExceptionpath. This PR implements the alternative suggested by the maintainer in the #171 review discussion:exceptclauses inrun()into a singleexcept Exceptionblock that type-checks forFaultException, soerror_resultis built exactly as before for both paths.post_init_error(andsys.exit(1)) inside theexceptblock, restoringsys.exc_info()availability while keeping error reporting behavior identical.sys.exc_info()inside a mockedpost_init_errorand assert the active exception is visible: one for theFaultExceptionpath (bad handler) and one for the generic exception path.No behavior change otherwise: both exception types still log the unhandled-exception warning, report the error via
post_init_error, and exit with code 1.on_init_complete()already callspost_init_errorinside itsexceptblock, so no change was needed there.Tested with
make test: 126 tests pass, coverage 95% (gate is 90%),black --checkclean.Target (OCI, Managed Runtime, both): both
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.