Skip to content
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

[DIC] Improve error message when a service is badly configured #31265

Closed
lyrixx opened this issue Apr 26, 2019 · 1 comment
Closed

[DIC] Improve error message when a service is badly configured #31265

lyrixx opened this issue Apr 26, 2019 · 1 comment
Labels
DependencyInjection RFC RFC = Request For Comments (proposals about features that you want to be discussed)

Comments

@lyrixx
Copy link
Member

lyrixx commented Apr 26, 2019

When making this typo:

    App\Word\WordChecker:
        arguments:
            checkers:
                - '@App\Word\Checker\StaticWordChecker'
                - '@App\Word\Checker\BannedWorldListChecker'

The error is the following:

Invalid service "App\Word\WordChecker": the value of argument "checkers" of method "__construct()" must be null, an instance of Symfony\Component\DependencyInjection\Reference or an instance of Symfony\Component\DependencyInjection\Definition, array given.

Honestly, I don't understand the error. IMHO, we could improve it

We could add Did you forgot to prefix $ to checkers ?

(Question: Did you get the error at the first glance ? 😂 )

@lyrixx lyrixx added DependencyInjection RFC RFC = Request For Comments (proposals about features that you want to be discussed) labels Apr 26, 2019
@Simperfit
Copy link
Contributor

I got it once :p.

@fabpot fabpot closed this as completed Apr 29, 2019
fabpot added a commit that referenced this issue Apr 29, 2019
…ument (jschaedl)

This PR was squashed before being merged into the 4.3-dev branch (closes #31306).

Discussion
----------

[DI] Improve exception message on missing $ of named argument

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | -
| New feature?  | -
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- don't forget to update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | #31265   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | not related
<!--
Write a short README entry for your feature/bugfix here (replace this comment block.)
This will help people understand your PR and can be used as a start of the Doc PR.
Additionally:
 - Bug fixes must be submitted against the lowest branch where they apply
   (lowest branches are regularly merged to upper ones so they get the fixes too).
 - Features and deprecations must be submitted against the master branch.
-->

### Description

As described in #31265, missing the prefix `$` in an argument name:

```
    App\Word\WordChecker:
        arguments:
            checkers:
                - '@app\Word\Checker\StaticWordChecker'
                - '@app\Word\Checker\BannedWorldListChecker'
```

led to the following error:

`Invalid service "App\Word\WordChecker": the value of argument "checkers" of method "__construct()" must be null, an instance of Symfony\Component\DependencyInjection\Reference or an instance of Symfony\Component\DependencyInjection\Definition, array given.`

As this error message is quite confusing I changed it to:

`Invalid service "App\Word\WordChecker":  Did you forget to add the "$" prefix to argument checkers`

### Todo

- [x] add a unit test

Commits
-------

d0e4499 [DI] Improve exception message on missing $ of named argument
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DependencyInjection RFC RFC = Request For Comments (proposals about features that you want to be discussed)
Projects
None yet
Development

No branches or pull requests

3 participants