Skip to content

Commit 1b36d03

Browse files
committed
minor symfony#25663 [DX] [DI] Improve exception for invalid setter injection arguments (curry684)
This PR was merged into the 3.4 branch. Discussion ---------- [DX] [DI] Improve exception for invalid setter injection arguments | Q | A | ------------- | --- | Branch? | 4.0 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no <!-- don't forget to update UPGRADE-*.md files --> | Tests pass? | yes | License | MIT Improve the exception message for when you accidentally write setter injection wrong as I did too many times: ```yaml My\Logging\Service: calls: [ [ setLogger, "@logger" ] ] ``` Used to throw: > Type error: Argument 2 passed to Symfony\Component\DependencyInjection\Definition::addMethodCall() must be of the type array, object given, called in /var/www/project/vendor/symfony/dependency-injection/Loader/YamlFileLoader.php on line 457 Now throws: > The second parameter for function call "setLogger" must be an array of its arguments for service "My\Namespace\Service" in /var/www/project/config/services.yaml. Check your YAML syntax in /var/www/project/config/services.yaml (which is loaded in resource "/var/www/project/config/services.yaml"). (semi-offtopic: why isn't `LoggerAwareInterface` in the default autoconfigure for FrameworkExtension?) Commits ------- 6850a22 [DX] [DI] Improve exception for invalid setter injection arguments
2 parents a483d37 + 6850a22 commit 1b36d03

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,9 @@ private function parseDefinition($id, $service, $file, array $defaults)
476476
$args = isset($call[1]) ? $this->resolveServices($call[1], $file) : array();
477477
}
478478

479+
if (!is_array($args)) {
480+
throw new InvalidArgumentException(sprintf('The second parameter for function call "%s" must be an array of its arguments for service "%s" in %s. Check your YAML syntax.', $method, $id, $file));
481+
}
479482
$definition->addMethodCall($method, $args);
480483
}
481484
}

0 commit comments

Comments
 (0)