Skip to content

fix: error handlers that take args: Args crashed instead of running - #1592

Open
sahiljagtap08 wants to merge 1 commit into
slackapi:mainfrom
sahiljagtap08:fix/args-in-error-handlers
Open

sahiljagtap08 wants to merge 1 commit into
slackapi:mainfrom
sahiljagtap08:fix/args-in-error-handlers

Conversation

@sahiljagtap08

@sahiljagtap08 sahiljagtap08 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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

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

No deployments
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.

Error handlers that take args: Args crash with a missing 'next' argument

1 participant