Skip to content

[Messenger] Improved message when handler class does not exist #29226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

neeckeloo
Copy link
Contributor

@neeckeloo neeckeloo commented Nov 15, 2018

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets
License MIT
Doc PR

Problem:

When defining a non existing messenger handler class in the services.yml config file, we encounter this confusing error message:

services:
    App\Handler\NonExistentHandler:
        tags: [messenger.message_handler]
PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to Symfony\Component\Messenger\DependencyInjection\MessengerPass::guessHandledClasses() must be an instance of ReflectionClass, null given, called in /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php on line 93 in /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php:189
Stack trace:
    #0 /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php(93): Symfony\Component\Messenger\DependencyInjection\MessengerPass->guessHandledClasses(NULL, 'App\\Application...')
    #1 /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php(74): Symfony\Component\Messenger\DependencyInjection\MessengerPass->registerHandlers(Object(Symfony\Component\DependencyInjection\ContainerBuilder), Array)
    #2 /app/vendor/symfony/dependency-injection/Compiler/Compiler.php(95): Symfony\Component\Messenger\DependencyInjection\MessengerPass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
    #3 / in /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php on line 189

Proposal:

We can throw a more relevant exception (RuntimeException) in this case to help the developer to have a better understanding of the issue.

Invalid service "App\Handler\NonExistentHandler": class "App\Handler\NonExistentHandler" does not exist.

@neeckeloo neeckeloo changed the title Improved message when messenger handler class does not exist [Messenger] Improved message when handler class does not exist Nov 15, 2018
@neeckeloo neeckeloo force-pushed the dedicated_exception_to_unknown_handler_class branch from 733eae5 to 62d9634 Compare November 15, 2018 10:41
@neeckeloo neeckeloo force-pushed the dedicated_exception_to_unknown_handler_class branch from 62d9634 to ad68373 Compare November 15, 2018 10:59
@neeckeloo neeckeloo force-pushed the dedicated_exception_to_unknown_handler_class branch from ad68373 to 6ab9274 Compare November 15, 2018 11:00
@nicolas-grekas nicolas-grekas added this to the 4.2 milestone Nov 15, 2018
@nicolas-grekas
Copy link
Member

Thank you @neeckeloo.

@nicolas-grekas nicolas-grekas merged commit 6ab9274 into symfony:master Nov 15, 2018
nicolas-grekas added a commit that referenced this pull request Nov 15, 2018
…xist (neeckeloo)

This PR was merged into the 4.2-dev branch.

Discussion
----------

[Messenger] Improved message when handler class does not exist

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? |no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

**Problem:**

When defining a non existing messenger handler class in the `services.yml` config file, we encounter this confusing error message:

```
services:
    App\Handler\NonExistentHandler:
        tags: [messenger.message_handler]
```

```
PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Argument 1 passed to Symfony\Component\Messenger\DependencyInjection\MessengerPass::guessHandledClasses() must be an instance of ReflectionClass, null given, called in /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php on line 93 in /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php:189
Stack trace:
    #0 /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php(93): Symfony\Component\Messenger\DependencyInjection\MessengerPass->guessHandledClasses(NULL, 'App\\Application...')
    #1 /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php(74): Symfony\Component\Messenger\DependencyInjection\MessengerPass->registerHandlers(Object(Symfony\Component\DependencyInjection\ContainerBuilder), Array)
    #2 /app/vendor/symfony/dependency-injection/Compiler/Compiler.php(95): Symfony\Component\Messenger\DependencyInjection\MessengerPass->process(Object(Symfony\Component\DependencyInjection\ContainerBuilder))
    #3 / in /app/vendor/symfony/messenger/DependencyInjection/MessengerPass.php on line 189
```

**Proposal:**

We can throw a more relevant exception (RuntimeException) in this case to help the developer to have a better understanding of the issue.

```Invalid service "App\Handler\NonExistentHandler": class "App\Handler\NonExistentHandler" does not exist.```

Commits
-------

6ab9274 Improve error message when defining messenger handler class that does not exists
@neeckeloo neeckeloo deleted the dedicated_exception_to_unknown_handler_class branch November 15, 2018 13:33
@fabpot fabpot mentioned this pull request Nov 16, 2018
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.

4 participants