Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23b5b25

Browse files
committed
improved message when alias service is not found
When using the YAML config format, it can be confusing that you need to prefix the aliased service id with an `@` character when passing it as a string, but that you have to omit it when using the `alias` attribute: ```yaml foo: '@app\Foo' foo: alias: 'App\Foo' ``` This commit will enhance the generated error message in cases where the aliased service id is prefixed with the `@` character in the `alias` option like this: ```yaml foo: alias: '@app\Foo' ```
1 parent 86a5d92 commit 23b5b25

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,13 @@ public function process(ContainerBuilder $container)
5858
try {
5959
$definition = $container->getDefinition($targetId);
6060
} catch (InvalidArgumentException $e) {
61-
throw new InvalidArgumentException(sprintf('Unable to replace alias "%s" with actual definition "%s".', $definitionId, $targetId), null, $e);
61+
$message = sprintf('Unable to replace alias "%s" with actual definition "%s".', $definitionId, $targetId);
62+
63+
if ('' !== $targetId && '@' === $targetId[0]) {
64+
$message .= sprintf(' Did you mean "%s"?', substr($targetId, 1));
65+
}
66+
67+
throw new InvalidArgumentException($message, null, $e);
6268
}
6369
if ($definition->isPublic()) {
6470
continue;

0 commit comments

Comments
 (0)