Repository navigation
fix: error handlers that take args: Args crashed instead of running - #1592
Open
sahiljagtap08 wants to merge 1 commit into
Open
sahiljagtap08 wants to merge 1 commit into
sahiljagtap08 wants to merge 1 commit into
Conversation
Error handlers, listener start/completion handlers and middleware error handlers build their kwargs with next_keys_required=False, which removed next/next_ from the available args. Args.__init__ requires next, so a handler declared as (args: Args) raised TypeError and never ran. The original error was then lost. - Keep next/next_ available for building Args and only skip injecting them as direct kwargs when there is no middleware chain - Add an error field to Args and AsyncArgs so error handlers can read the exception through args - Add sync and async tests for an error handler that takes args
This branch has not been deployed
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.
Summary
An error handler declared as
def handler(args: Args)never ran. Error handlers, listener start/completion handlers, and middleware error handlers all build their kwargs withnext_keys_required=False. That removednextandnext_from the available arguments, butArgs.__init__requiresnext, so building theArgsobject raised:The handler was skipped and the original listener error was lost with it. The async variant had the same problem.
Changes:
slack_bolt/kwargs_injection/utils.pyandasync_utils.py:nextandnext_stay in the available arguments soArgscan be built. They are only left out when injecting direct keyword arguments for handlers that have no middleware chain, which keeps the existing behaviour for those handlers.slack_bolt/kwargs_injection/args.pyandasync_args.py: add an optionalerrorfield so an error handler can read the exception throughargs.error. The value was already passed to the constructor but was dropped by**kwargs.Testing
Added
test_custom_with_argsto bothtests/scenario_tests/test_error_handler.pyandtests/scenario_tests_async/test_error_handler.py. Each registers an error handler that takesargs: Args, readsargs.error, and sets a response header. Both fail onmainand pass with this change. Ran./scripts/format.sh,./scripts/lint.sh,./scripts/run_mypy.sh, the error handler test files, the kwargs injection tests, and the middleware tests.Category
Requirements
./scripts/install_all_and_run_tests.shafter making the changes.Fixes #1598