You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature symfony#18547 DX: better error message if factory class is empty (dbu)
This PR was merged into the 3.1-dev branch.
Discussion
----------
DX: better error message if factory class is empty
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| BC breaks? | no
| Deprecations? | no
| Tests pass? | ?
| Fixed tickets | -
| License | MIT
| Doc PR | -
i was trying to debug this service configuration:
```xml
<service id="repository.user" class="Doctrine\ORM\EntityRepository">
<argument>%user_entity_class%</argument>
<factory id="doctrine.orm.default_entity_manager" method="getRepository"/>
</service>
```
Turns out i should have used `<factory service=...` instead of `<factory id=...` but the error message does not even tell which service is wrong. The same happens when only specifying the `method=` attribute. The current exception message tells:
Cannot dump definition because of invalid class name ('')
With this change, the message at least tells the context, hopefully helping the developer debug the issue:
Empty class for factory of service repository.user and no factory service specified
Commits
-------
0999326 better error message if factory class is empty
@@ -716,6 +716,10 @@ private function addNewInstance(Definition $definition, $return, $instantiation)
716
716
$class = $this->dumpValue($callable[0]);
717
717
// If the class is a string we can optimize call_user_func away
718
718
if (strpos($class, "'") === 0) {
719
+
if ("''" === $class) {
720
+
thrownewRuntimeException(sprintf('Cannot dump definition: The "%s" service is defined to be created by a factory but is missing the service reference, did you forget to define the factory service id or class?', $id));
0 commit comments