slimphp / slimphp/Slim

Resolving middleware breaks if resolver throws unexpected exception type

Open
#3,071 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Slim 4 Slim 5
Dominant language
PHP
Stars
12.3k
Forks
2k
Avg merge
3d 2h
Merged PRs (30d)
6

Description

CallableResolver call is wrapped in a catch that expects RuntimeException

https://github.com/slimphp/Slim/blob/8294d20e016b01ba57eb2cdb8c0f59cde502d1ab/Slim/MiddlewareDispatcher.php#L214-L222

If a resolver throws exception that doesn't extend from RuntimeException this halts the execution and fallback code below is never reached.

Real example of the issue with third party resolver: https://github.com/PHP-DI/Slim-Bridge/issues/51

I am not sure what's the reasoning for specifically RuntimeException here, but broadening it to Exception might be a good idea for resilience?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in Slim/MiddlewareDispatcher.php around lines 214–222 and inspect how CallableResolver exceptions are caught before the fallback path. Reproduce the case with a resolver that throws an exception outside RuntimeException, then verify that the fallback code is reached without halting middleware execution.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.