8000 bug #27143 [Console] By default hide the short exception trace line f… · symfony/symfony@278f40f · GitHub
[go: up one dir, main page]

Skip to content

Commit 278f40f

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 #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 ------- 11f3c45 Hide short exception trace by default
2 parents 7bbadf5 + 11f3c45 commit 278f40f

17 files changed

+49
-28
lines changed

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Bridge\Twig\Command;
1313

1414
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Exception\InvalidArgumentException;
16+
use Symfony\Component\Console\Exception\RuntimeException;
1517
use Symfony\Component\Console\Input\InputArgument;
1618
use Symfony\Component\Console\Input\InputInterface;
1719
use Symfony\Component\Console\Input\InputOption;
@@ -119,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
119121

120122
if (0 === count($filenames)) {
121123
if (0 !== ftell(STDIN)) {
122-
throw new \RuntimeException('Please provide a filename or pipe template content to STDIN.');
124+
throw new RuntimeException('Please provide a filename or pipe template content to STDIN.');
123125
}
124126

125127
$template = '';
@@ -155,7 +157,7 @@ protected function findFiles($filename)
155157
return Finder::create()->files()->in($filename)->name('*.twig');
156158
}
157159

158-
throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
160+
throw new RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
159161
}
160162

161163
private function validate($template, $file)
@@ -184,7 +186,7 @@ private function display(InputInterface $input, OutputInterface $output, Symfony
184186
case 'json':
185187
return $this->displayJson($output, $files);
186188
default:
187-
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format')));
189+
throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $input->getOption('format')));
188190
}
189191
}
190192

src/Symfony/Bundle/FrameworkBundle/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)

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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)));

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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));

src/Symfony/Bundle/FrameworkBundle/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;

src/Symfony/Bundle/FrameworkBundle/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);

src/Symfony/Bundle/FrameworkBundle/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')) {

src/Symfony/Bundle/FrameworkBundle/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
}

src/Symfony/Bundle/FrameworkBundle/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();

src/Symfony/Bundle/SecurityBundle/Command/SetAclCommand.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
@trigger_error(sprintf('Class "%s" is deprecated since Symfony 3.4 and will be removed in 4.0. Use Symfony\Bundle\AclBundle\Command\SetAclCommand instead.', SetAclCommand::class), E_USER_DEPRECATED);
1515

1616
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
17+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1718
use Symfony\Component\Console\Input\InputArgument;
1819
use Symfony\Component\Console\Input\InputInterface;
1920
use Symfony\Component\Console\Input\InputOption;
@@ -144,7 +145,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
144145
$classScopeOption = $input->getOption('class-scope');
145146

146147
if (empty($userOption) && empty($roleOption)) {
147-
throw new \InvalidArgumentException('A Role or a User must be specified.');
148+
throw new InvalidArgumentException('A Role or a User must be specified.');
148149
}
149150

150151
// Create security identities
@@ -155,7 +156,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
155156
$data = explode(':', $user, 2);
156157

157158
if (1 === count($data)) {
158-
throw new \InvalidArgumentException('The user must follow the format "Acme/MyUser:username".');
159+
throw new InvalidArgumentException('The user must follow the format "Acme/MyUser:username".');
159160
}
160161

161162
$securityIdentities[] = new UserSecurityIdentity($data[1], strtr($data[0], '/', '\\'));

src/Symfony/Bundle/SecurityBundle/Command/UserPasswordEncoderCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Bundle\SecurityBundle\Command;
1313

1414
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
15+
use Symfony\Component\Console\Exception\InvalidArgumentException;
16+
use Symfony\Component\Console\Exception\RuntimeException;
1517
use Symfony\Component\Console\Input\InputArgument;
1618
use Symfony\Component\Console\Input\InputInterface;
1719
use Symfony\Component\Console\Input\InputOption;
@@ -179,7 +181,7 @@ private function createPasswordQuestion()
179181

180182
return $passwordQuestion->setValidator(function ($value) {
181183
if ('' === trim($value)) {
182-
throw new \Exception('The password must not be empty.');
184+
throw new InvalidArgumentException('The password must not be empty.');
183185
}
184186

185187
return $value;
@@ -203,7 +205,7 @@ private function getUserClass(InputInterface $input, SymfonyStyle $io)
203205
return User::class;
204206
}
205207

206-
throw new \RuntimeException('There are no configured encoders for the "security" extension.');
208+
throw new RuntimeException('There are no configured encoders for the "security" extension.');
207209
}
208210

209211
if (!$input->isInteractive() || 1 === count($this->userClasses)) {

src/Symfony/Bundle/WebServerBundle/Command/ServerLogCommand.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
1616
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
1717
use Symfony\Component\Console\Command\Command;
18+
use Symfony\Component\Console\Exception\LogicException;
19+
use Symfony\Component\Console\Exception\RuntimeException;
1820
use Symfony\Component\Console\Input\InputInterface;
1921
use Symfony\Component\Console\Input\InputOption;
2022
use Symfony\Component\Console\Output\OutputInterface;
@@ -78,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7880
$filter = $input->getOption('filter');
7981
if ($filter) {
8082
if (!class_exists(ExpressionLanguage::class)) {
81-
throw new \LogicException('Package "symfony/expression-language" is required to use the "filter" option.');
83+
throw new LogicException('Package "symfony/expression-language" is required to use the "filter" option.');
8284
}
8385
$this->el = new ExpressionLanguage();
8486
}
@@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
9799
}
98100

99101
if (!$socket = stream_socket_server($host, $errno, $errstr)) {
100-
throw new \RuntimeException(sprintf('Server start failed on "%s": %s %s.', $host, $errstr, $errno));
102+
throw new RuntimeException(sprintf('Server start f 341A ailed on "%s": %s %s.', $host, $errstr, $errno));
101103
}
102104

103105
foreach ($this->getLogs($socket) as $clientId => $message) {

src/Symfony/Bundle/WebServerBundle/Command/ServerStatusCommand.php

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

1414
use Symfony\Bundle\WebServerBundle\WebServer;
15+
use Symfony\Component\Console\Exception\InvalidArgumentException;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -73,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7374
} elseif ('port' === $filter) {
7475
$output->write($port);
7576
} else {
76-
throw new \InvalidArgumentException(sprintf('"%s" is not a valid filter.', $filter));
77+
throw new InvalidArgumentException(sprintf('"%s" is not a valid filter.', $filter));
7778
}
7879
} else {
7980
return 1;

src/Symfony/Component/Translation/Command/XliffLintCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Translation\Command;
1313

1414
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Exception\RuntimeException;
1516
use Symfony\Component\Console\Input\InputInterface;
1617
use Symfony\Component\Console\Input\InputOption;
1718
use Symfony\Component\Console\Output\OutputInterface;
@@ -81,14 +82,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
8182

8283
if (!$filename) {
8384
if (!$stdin = $this->getStdin()) {
84-
throw new \RuntimeException('Please provide a filename or pipe file content to STDIN.');
85+
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
8586
}
8687

8788
return $this->display($io, array($this->validate($stdin)));
8889
}
8990

9091
if (!$this->isReadable($filename)) {
91< 10000 span class="diff-text-marker">-
throw new \RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
92+
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
9293
}
9394

9495
$filesInfo = array();
@@ -136,7 +137,7 @@ private function display(SymfonyStyle $io, array $files)
136137
case 'json':
137138
return $this->displayJson($io, $files);
138139
default:
139-
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
140+
throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
140141
}
141142
}
142143

src/Symfony/Component/Yaml/Command/LintCommand.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
namespace Symfony\Component\Yaml\Command;
1313

1414
use Symfony\Component\Console\Command\Command;
15+
use Symfony\Component\Console\Exception\InvalidArgumentException;
16+
use Symfony\Component\Console\Exception\RuntimeException;
1517
use Symfony\Component\Console\Input\InputInterface;
1618
use Symfony\Component\Console\Input\InputOption;
1719
use Symfony\Component\Console\Output\OutputInterface;
@@ -86,14 +88,14 @@ protected function execute(InputInterface $input, OutputInterface $output)
8688

8789
if (!$filename) {
8890
if (!$stdin = $this->getStdin()) {
89-
throw new \RuntimeException('Please provide a filename or pipe file content to STDIN.');
91+
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
9092
}
9193

9294
return $this->display($io, array($this->validate($stdin, $flags)));
9395
}
9496

9597
if (!$this->isReadable($filename)) {
96-
throw new \RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
98+
throw new RuntimeException(sprintf('File or directory "%s" is not readable.', $filename));
9799
}
98100

99101
$filesInfo = array();
@@ -133,7 +135,7 @@ private function display(SymfonyStyle $io, array $files)
133135
case 'json':
134136
return $this->displayJson($io, $files);
135137
default:
136-
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
138+
throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
137139
}
138140
}
139141

0 commit comments

Comments
 (0)
0