8000 [DI] Confusing error message when an argument can't be autowired · Issue #22848 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[DI] Confusing error message when an argument can't be autowired #22848
Closed
@javiereguiluz

Description

@javiereguiluz
Q A
Bug report? yes?
Feature request? no
BC Break report? no
Symfony version 3.3

In symfony/demo#562 we're updating the Symfony Demo app to 3.3.0 RC1 and all the new DI features. During the upgrade I suffered lots of errors ... but the error messages were perfect. Examples:

AutowiringFailedException in AutowirePass.php line 271:
Cannot autowire service "AppBundle\EventListener\CommentNotificationSubscriber":
argument "$sender" of method "__construct()" must have a type-hint or be given a
value explicitly.

AutowiringFailedException in AutowirePass.php line 271: Cannot autowire service
"AppBundle\EventListener\RedirectToPreferredLocaleSubscriber": argument
"$locales" of method "__construct()" must have a type-hint or be given a value
explicitly.

However, when I removed this original service config for our Twig extension:

app.twig.app_extension:
    public:    false
    class:     AppBundle\Twig\AppExtension
    arguments: ['@markdown', '%app_locales%']
    tags:
        - { name: twig.extension }

I saw this confusing error:

FatalThrowableError in AppExtension.php line 42:
Type error: Too few arguments to function
AppBundle\Twig\AppExtension::__construct(), 0 passed in /Users/javier/sf
/symfony-demo/var/cache/dev/appDevDebugProjectContainer.php on line 3565 and
exactly 2 expected

This was fixed when I added this:

AppBundle\Twig\AppExtension:
    arguments:
        $locales: '%app_locales%'

Why did I see a different error message in this case? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0