Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6894e03

Browse filesBrowse files
committed
Make failed autowiring error messages more explicit
1 parent c86a1a1 commit 6894e03
Copy full SHA for 6894e03

File tree

2 files changed

+10
-3
lines changed
Filter options

2 files changed

+10
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Compiler/AutowirePass.php
+9-2Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Compiler/AutowirePassTest.php
+1-1Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.