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 with next_keys_required=False. That removed next and next_ from the available arguments, but Args.__init__ requires next, so building the Args object raised:
TypeError: Args.__init__() missing 1 required keyword-only argument: 'next'
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.py and async_utils.py: next and next_ stay in the available arguments so Args can 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.py and async_args.py: add an optional error field so an error handler can read the exception through args.error. The value was already passed to the constructor but was dropped by **kwargs.
Testing
Added test_custom_with_args to both tests/scenario_tests/test_error_handler.py and tests/scenario_tests_async/test_error_handler.py. Each registers an error handler that takes args: Args, reads args.error, and sets a response header. Both fail on main and 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
- slack_bolt.App and/or its core components
- slack_bolt.async_app.AsyncApp and/or its core components
- Adapters in slack_bolt.adapter
- Others
Requirements
- I've read and understood the Contributing Guidelines and have done my best effort to follow them.
- I've read and agree to the Code of Conduct.
- I've run
./scripts/install_all_and_run_tests.sh after making the changes.
Fixes #1598