From f1921364d692a521c5bf5860ce453bae3f9facae Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 7 Jan 2021 20:04:04 +0100 Subject: Print an exception trace for setup exceptions Right now any setup error will just result in the exception message being printed. In some cases this doesn't give any insights into what went wrong. This adds some dedicated logic to print the exception trace and any previous exceptions to the CLI. Signed-off-by: Christoph Wurst --- core/Command/Maintenance/Install.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'core/Command/Maintenance') diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index dffbbd03382..ed1aeeff922 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -43,6 +43,8 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; +use Throwable; +use function get_class; class Install extends Command { @@ -201,11 +203,25 @@ class Install extends Command { protected function printErrors(OutputInterface $output, $errors) { foreach ($errors as $error) { if (is_array($error)) { - $output->writeln('' . (string)$error['error'] . ''); - $output->writeln(' -> ' . (string)$error['hint'] . ''); + $output->writeln('' . $error['error'] . ''); + if (isset($error['hint']) && !empty($error['hint'])) { + $output->writeln(' -> ' . $error['hint'] . ''); + } + if (isset($error['exception']) && $error['exception'] instanceof Throwable) { + $this->printThrowable($output, $error['exception']); + } } else { - $output->writeln('' . (string)$error . ''); + $output->writeln('' . $error . ''); } } } + + private function printThrowable(OutputInterface $output, Throwable $t): void { + $output->write('Trace: ' . $t->getTraceAsString() . ''); + if ($t->getPrevious() !== null) { + $output->writeln(''); + $output->writeln('Previous: ' . get_class($t->getPrevious()) . ': ' . $t->getPrevious()->getMessage() . ''); + $this->printThrowable($output, $t->getPrevious()); + } + } } -- cgit v1.2.3