Skip to content

Commit 40937f6

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 a512730 commit 40937f6

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Command/ContainerDebugCommand.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use Symfony\Component\Console\Output\OutputInterface;
2323
use Symfony\Component\Console\Style\SymfonyStyle;
2424
use Symfony\Component\DependencyInjection\ContainerBuilder;
25+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
2526
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
2627
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
2728

@@ -144,7 +145,16 @@ protected function execute(InputInterface $input, OutputInterface $output)
144145
$options['show_hidden'] = $input->getOption('show-hidden');
145146
$options['raw_text'] = $input->getOption('raw');
146147
$options['output'] = $io;
147-
$helper->describe($io, $object, $options);
148+
149+
try {
150+
$helper->describe($io, $object, $options);
151+
} catch (ServiceNotFoundException $e) {
152+
if ('' !== $e->getId() && '@' === $e->getId()[0]) {
153+
throw new ServiceNotFoundException($e->getId(), $e->getSourceId(), null, array(substr($e->getId(), 1)));
154+
}
155+
156+
throw $e;
157+
}
148158

149159
if (!$input->getArgument('name') && !$input->getOption('tag') && !$input->getOption('parameter') && $input->isInteractive()) {
150160
if ($input->getOption('tags')) {

0 commit comments

Comments
 (0)