Skip to content

Commit 47012d9

Browse files
bug #27143 [Console] By default hide the short exception trace line from exception messages in Symfony's commands (yceruto)
This PR was merged into the 3.4 branch. Discussion ---------- [Console] By default hide the short exception trace line from exception messages in Symfony's commands | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - After symfony/symfony#24131 this was in my contribution list since then. Maybe it should be taken as a good practice when we build console commands, **use the exception classes of the Console component as much as possible to show a better message style to the end user**. (See the before/after effect in the referenced PR) Commits ------- 11f3c455d4 Hide short exception trace by default
2 parents 60cd297 + ba58562 commit 47012d9

10 files changed

+22
-12
lines changed

Command/AbstractConfigCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

1414
use Symfony\Component\Config\Definition\ConfigurationInterface;
15+
use Symfony\Component\Console\Exception\LogicException;
1516
use Symfony\Component\Console\Helper\Table;
1617
use Symfony\Component\Console\Style\StyleInterface;
1718
use Symfony\Component\DependencyInjection\Extension\ExtensionInterface;
@@ -98,7 +99,7 @@ protected function findExtension($name)
9899
$message .= sprintf("\n\nDid you mean \"%s\"?", $guess);
99100
}
100101

101-
throw new \LogicException($message);
102+
throw new LogicException($message);
102103
}
103104

104105
public function validateConfiguration(ExtensionInterface $extension, $configuration)

Command/AssetsInstallCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1415
use Symfony\Component\Console\Input\InputArgument;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputOption;
@@ -115,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
115116
if (is_dir(dirname($targetArg).'/web')) {
116117
$targetArg = dirname($targetArg).'/web';
117118
} else {
118-
throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
119+
throw new InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
119120
}
120121
}
121122
}

Command/CacheClearCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14+
use Symfony\Component\Console\Exception\RuntimeException;
1415
use Symfony\Component\Console\Input\InputInterface;
1516
use Symfony\Component\Console\Input\InputOption;
1617
use Symfony\Component\Console\Output\OutputInterface;
@@ -104,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
104105
$fs->remove($oldCacheDir);
105106

106107
if (!is_writable($realCacheDir)) {
107-
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
108+
throw new RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
108109
}
109110

110111
$io->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));

Command/CachePoolClearCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

1414
use Psr\Cache\CacheItemPoolInterface;
15+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -93,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9394
} elseif ($pool instanceof Psr6CacheClearer) {
9495
$clearers[$id] = $pool;
9596
} else {
96-
throw new \InvalidArgumentException(sprintf('"%s" is not a cache pool nor a cache clearer.', $id));
97+
throw new InvalidArgumentException(sprintf('"%s" is not a cache pool nor a cache clearer.', $id));
9798
}
9899
}
99100
}

Command/ConfigDumpReferenceCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper;
1515
use Symfony\Component\Config\Definition\Dumper\XmlReferenceDumper;
16+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Input\InputInterface;
@@ -124,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
124125
break;
125126
default:
126127
$io->writeln($message);
127-
throw new \InvalidArgumentException('Only the yaml and xml formats are supported.');
128+
throw new InvalidArgumentException('Only the yaml and xml formats are supported.');
128129
}
129130

130131
$io->writeln(null === $path ? $dumper->dump($configuration, $extension->getNamespace()) : $dumper->dumpAtPath($configuration, $path));

Command/ContainerDebugCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
1515
use Symfony\Component\Config\ConfigCache;
16+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputOption;
1819
use Symfony\Component\Console\Input\InputInterface;
@@ -167,9 +168,9 @@ protected function validateInput(InputInterface $input)
167168

168169
$name = $input->getArgument('name');
169170
if ((null !== $name) && ($optionsCount > 0)) {
170-
throw new \InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined with the service name argument.');
171+
throw new InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined with the service name argument.');
171172
} elseif ((null === $name) && $optionsCount > 1) {
172-
throw new \InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined together.');
173+
throw new InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined together.');
173174
}
174175
}
175176

@@ -208,7 +209,7 @@ private function findProperServiceName(InputInterface $input, SymfonyStyle $io,
208209

209210
$matchingServices = $this->findServiceIdsContaining($builder, $name);
210211
if (empty($matchingServices)) {
211-
throw new \InvalidArgumentException(sprintf('No services found that match "%s".', $name));
212+
throw new InvalidArgumentException(sprintf('No services found that match "%s".', $name));
212213
}
213214

214215
$default = 1 === count($matchingServices) ? $matchingServices[0] : null;

Command/RouterDebugCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
1515
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
16+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1617
use Symfony\Component\Console\Input\InputArgument;
1718
use Symfony\Component\Console\Input\InputInterface;
1819
use Symfony\Component\Console\Input\InputOption;
@@ -116,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
116117

117118
if ($name) {
118119
if (!$route = $routes->get($name)) {
119-
throw new \InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
120+
throw new InvalidArgumentException(sprintf('The route "%s" does not exist.', $name));
120121
}
121122

122123
$callable = $this->extractCallable($route);

Command/TranslationDebugCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1415
use Symfony\Component\Console\Style\SymfonyStyle;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputArgument;
@@ -182,7 +183,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
182183
$viewsPaths = array($input->getArgument('bundle').'/Resources/views');
183184

184185
if (!is_dir($transPaths[0])) {
185-
throw new \InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
186+
throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
186187
}
187188
}
188189
} elseif ($input->getOption('all')) {

Command/TranslationUpdateCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1415
use Symfony\Component\Console\Style\SymfonyStyle;
1516
use Symfony\Component\HttpKernel\KernelInterface;
1617
use Symfony\Component\Translation\Catalogue\TargetOperation;
@@ -192,7 +193,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
192193
$currentName = $transPaths[0];
193194

194195
if (!is_dir($transPaths[0])) {
195-
throw new \InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
196+
throw new InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
196197
}
197198
}
198199
}

Command/WorkflowDumpCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\FrameworkBundle\Command;
1313

14+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1415
use Symfony\Component\Console\Input\InputArgument;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Output\OutputInterface;
@@ -63,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6364
$workflow = $container->get('state_machine.'.$serviceId);
6465
$dumper = new StateMachineGraphvizDumper();
6566
} else {
66-
throw new \InvalidArgumentException(sprintf('No service found for "workflow.%1$s" nor "state_machine.%1$s".', $serviceId));
67+
throw new InvalidArgumentException(sprintf('No service found for "workflow.%1$s" nor "state_machine.%1$s".', $serviceId));
6768
}
6869

6970
$marking = new Marking();

0 commit comments

Comments
 (0)