8000 Make failed autowiring error messages more explicit · symfony/symfony@6894e03 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6894e03

Browse files
committed
Make failed autowiring error messages more explicit
1 parent c86a1a1 commit 6894e03

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ private function createAutowiredDefinition(\ReflectionClass $typeHint, $id)
271271

272272
if (!$typeHint->isInstantiable()) {
273273
$classOrInterface = $typeHint->isInterface() ? 'interface' : 'class';
274-
throw new RuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". No services were found matching this %s.', $typeHint->name, $id, $classOrInterface));
274+
throw new RuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". No services were found matching this %s and it cannot be auto-registered.', $typeHint->name, $id, $classOrInterface));
275275
}
276276

277277
$argumentId = sprintf('autowired.%s', $typeHint->name);
@@ -280,7 +280,14 @@ private function createAutowiredDefinition(\ReflectionClass $typeHint, $id)
280280
$argumentDefinition->setPublic(false);
281281

282282
$this->populateAvailableType($argumentId, $argumentDefinition);
283-
$this->completeDefinition($argumentId, $argumentDefinition);
283+
284+
try {
285+
$this->completeDefinition($argumentId, $argumentDefinition);
286+
} catch (\RuntimeException $e) {
287+
$classOrInterface = $typeHint->isInterface() ? 'interface' : 'class';
288+
$message = sprintf('Unable to autowire argument of type "%s" for the service "%s". No services were found matching this %s and it cannot be auto-registered.', $typeHint->name, $id, $classOrInterface);
289+
throw new RuntimeException($message, 0, $e);
290+
}
284291

285292
return new Reference($argumentId);
286293
}

src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ public function testTypeNotGuessableWithSubclass()
155155

156156
/**
157157
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
158-
* @expectedExceptionMessage Unable to autowire argument of type "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" for the service "a". No services were found matching this interface.
158+
* @expectedExceptionMessage Unable to autowire argument of type "Symfony\Component\DependencyInjection\Tests\Compiler\CollisionInterface" for the service "a". No services were found matching this interface and it cannot be auto-registered.
159159
*/
160160
public function testTypeNotGuessableNoServicesFound()
161161
{

0 commit comments

Comments
 (0)
0