8000 [Console] By default hide the short exception trace line from exception messages in Symfony's commands by yceruto · Pull Request #27143 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Console] By default hide the short exception trace line from exception messages in Symfony's commands #27143

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Hide short exception trace by default
  • Loading branch information
yceruto committed May 3, 2018
commit 11f3c455d4b2949c4a04f4e34e709a9adaf01b64
8 changes: 5 additions & 3 deletions src/Symfony/Bridge/Twig/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Bridge\Twig\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -119,7 +121,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

if (0 === count($filenames)) {
if (0 !== ftell(STDIN)) {
throw new \RuntimeException('Please provide a filename or pipe template content to STDIN.');
throw new RuntimeException('Please provide a filename or pipe template content to STDIN.');
}

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

throw new \RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
throw new RuntimeException(sprintf('File or directory "%s" is not readable', $filename));
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Command;

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

throw new \LogicException($message);
throw new LogicException($message);
}

public function validateConfiguration(ExtensionInterface $extension, $configuration)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\Command;

use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -115,7 +116,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (is_dir(dirname($targetArg).'/web')) {
$targetArg = dirname($targetArg).'/web';
} else {
throw new \InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
throw new InvalidArgumentException(sprintf('The target directory "%s" does not exist.', $input->getArgument('target')));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\Command;

use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -104,7 +105,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$fs->remove($oldCacheDir);

if (!is_writable($realCacheDir)) {
throw new \RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
throw new RuntimeException(sprintf('Unable to write in the "%s" directory', $realCacheDir));
}

$io->comment(sprintf('Clearing the cache for the <info>%s</info> environment with debug <info>%s</info>', $kernel->getEnvironment(), var_export($kernel->isDebug(), true)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\FrameworkBundle\Command;

use Psr\Cache\CacheItemPoolInterface;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -93,7 +94,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} elseif ($pool instanceof Psr6CacheClearer) {
$clearers[$id] = $pool;
} else {
throw new \InvalidArgumentException(sprintf('"%s" is not a cache pool nor a cache clearer.', $id));
throw new InvalidArgumentException(sprintf('"%s" is not a cache pool nor a cache clearer.', $id));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Component\Config\Definition\Dumper\YamlReferenceDumper;
use Symfony\Component\Config\Definition\Dumper\XmlReferenceDumper;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -124,7 +125,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
break;
default:
$io->writeln($message);
throw new \InvalidArgumentException('Only the yaml and xml formats are supported.');
throw new InvalidArgumentException('Only the yaml and xml formats are supported.');
}

$io->writeln(null === $path ? $dumper->dump($configuration, $extension->getNamespace()) : $dumper->dumpAtPath($configuration, $path));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
use Symfony\Component\Config\ConfigCache;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -167,9 +168,9 @@ protected function validateInput(InputInterface $input)

$name = $input->getArgument('name');
if ((null !== $name) && ($optionsCount > 0)) {
throw new \InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined with the service name argument.');
throw new InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined with the service name argument.');
} elseif ((null === $name) && $optionsCount > 1) {
throw new \InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined together.');
throw new InvalidArgumentException('The options tags, tag, parameters & parameter can not be combined together.');
}
}

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

$matchingServices = $this->findServiceIdsContaining($builder, $name);
if (empty($matchingServices)) {
throw n 10000 ew \InvalidArgumentException(sprintf('No services found that match "%s".', $name));
throw new InvalidArgumentException(sprintf('No services found that match "%s".', $name));
}

$default = 1 === count($matchingServices) ? $matchingServices[0] : null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Symfony\Bundle\FrameworkBundle\Console\Helper\DescriptorHelper;
use Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -116,7 +117,7 @@ protected function execute(InputInterface $input, OutputInterface $output)

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

$callable = $this->extractCallable($route);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\Command;

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

if (!is_dir($transPaths[0])) {
throw new \InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
throw new InvalidArgumentException(sprintf('"%s" is neither an enabled bundle nor a directory.', $transPaths[0]));
}
}
} elseif ($input->getOption('all')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\Command;

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

if (!is_dir($transPaths[0])) {
throw new \InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
throw new InvalidArgumentException(sprintf('<error>"%s" is neither an enabled bundle nor a directory.</error>', $transPaths[0]));
}
}
}
Expand Down
10000
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Symfony\Bundle\FrameworkBundle\Command;

use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -63,7 +64,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$workflow = $container->get('state_machine.'.$serviceId);
$dumper = new StateMachineGraphvizDumper();
} else {
throw new \InvalidArgumentException(sprintf('No service found for "workflow.%1$s" nor "state_machine.%1$s".', $serviceId));
throw new InvalidArgumentException(sprintf('No service found for "workflow.%1$s" nor "state_machine.%1$s".', $serviceId));
}

$marking = new Marking();
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Bundle/SecurityBundle/Command/SetAclCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@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);

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -144,7 +145,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$classScopeOption = $input->getOption('class-scope');

if (empty($userOption) && empty($roleOption)) {
throw new \InvalidArgumentException('A Role or a User must be specified.');
throw new InvalidArgumentException('A Role or a User must be specified.');
}

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

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

$securityIdentities[] = new UserSecurityIdentity($data[1], strtr($data[0], '/', '\\'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Bundle\SecurityBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
Expand Down Expand Up @@ -179,7 +181,7 @@ private function createPasswordQuestion()

return $passwordQuestion->setValidator(function ($value) {
10000 if ('' === trim($value)) {
throw new \Exception('The password must not be empty.');
throw new InvalidArgumentException('The password must not be empty.');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chalasr It feels like a visual bug, so we're fixing the visual representation of the message, what do you think?

}

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

throw new \RuntimeException('There are no configured encoders for the "security" extension.');
throw new RuntimeException('There are no configured encoders for the "security" extension.');
}

if (!$input->isInteractive() || 1 === count($this->userClasses)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
use Symfony\Bridge\Monolog\Formatter\ConsoleFormatter;
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\LogicException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -78,7 +80,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filter = $input->getOption('filter');
if ($filter) {
if (!class_exists(ExpressionLanguage::class)) {
throw new \LogicException('Package "symfony/expression-language" is required to use the "filter" option.');
throw new LogicException('Package "symfony/expression-language" is required to use the "filter" option.');
}
$this->el = new ExpressionLanguage();
}
Expand All @@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

if (!$socket = stream_socket_server($host, $errno, $errstr)) {
throw new \RuntimeException(sprintf('Server start failed on "%s": %s %s.', $host, $errstr, $errno));
throw new RuntimeException(sprintf('Server start failed on "%s": %s %s.', $host, $errstr, $errno));
}

foreach ($this->getLogs($socket) as $clientId => $message) {
Expand Down
10000
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bundle\WebServerBundle\Command;

use Symfony\Bundle\WebServerBundle\WebServer;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -73,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
} elseif ('port' === $filter) {
$output->write($port);
} else {
throw new \InvalidArgumentException(sprintf('"%s" is not a valid filter.', $filter));
throw new InvalidArgumentException(sprintf('"%s" is not a valid filter.', $filter));
}
} else {
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Component\Translation\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -81,14 +82,14 @@ protected function execute(InputInterface $input, OutputInterface $output)

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

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

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

$filesInfo = array();
Expand Down Expand Up @@ -136,7 +137,7 @@ private function display(SymfonyStyle $io, array $files)
case 'json':
return $this->displayJson($io, $files);
default:
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/Symfony/Component/Yaml/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
namespace Symfony\Component\Yaml\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidArgumentException;
use Symfony\Component\Console\Exception\RuntimeException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -86,14 +88,14 @@ protected function execute(InputInterface $input, OutputInterface $output)

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

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

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

$filesInfo = array();
Expand Down Expand Up @@ -133,7 +135,7 @@ private function display(SymfonyStyle $io, array $files)
case 'json':
return $this->displayJson($io, $files);
default:
throw new \InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
throw new InvalidArgumentException(sprintf('The format "%s" is not supported.', $this->format));
}
}

Expand Down
0