Skip to content

Commit 82de641

Browse files
committed
feature #28449 [DependencyInjection] improved message when alias service is not found (xabbuh)
This PR was merged into the 4.2-dev branch. Discussion ---------- [DependencyInjection] improved message when alias service is not found | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #28413 | License | MIT | Doc PR | 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' ``` Commits ------- 280ecbc2be improved message when alias service is not found
2 parents 195d12c + 40937f6 commit 82de641

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)