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 <christoph@winzerhof-wurst.at>
This commit is contained in:
Christoph Wurst 2021-01-07 20:04:04 +01:00
parent 5020c73d15
commit f1921364d6
No known key found for this signature in database
GPG Key ID: CC42AC2A7F0E56D8
2 changed files with 23 additions and 3 deletions

View File

@ -43,6 +43,8 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\Question; use Symfony\Component\Console\Question\Question;
use Throwable;
use function get_class;
class Install extends Command { class Install extends Command {
@ -201,11 +203,25 @@ class Install extends Command {
protected function printErrors(OutputInterface $output, $errors) { protected function printErrors(OutputInterface $output, $errors) {
foreach ($errors as $error) { foreach ($errors as $error) {
if (is_array($error)) { if (is_array($error)) {
$output->writeln('<error>' . (string)$error['error'] . '</error>'); $output->writeln('<error>' . $error['error'] . '</error>');
$output->writeln('<info> -> ' . (string)$error['hint'] . '</info>'); if (isset($error['hint']) && !empty($error['hint'])) {
} else { $output->writeln('<info> -> ' . $error['hint'] . '</info>');
$output->writeln('<error>' . (string)$error . '</error>');
} }
if (isset($error['exception']) && $error['exception'] instanceof Throwable) {
$this->printThrowable($output, $error['exception']);
}
} else {
$output->writeln('<error>' . $error . '</error>');
}
}
}
private function printThrowable(OutputInterface $output, Throwable $t): void {
$output->write('<info>Trace: ' . $t->getTraceAsString() . '</info>');
if ($t->getPrevious() !== null) {
$output->writeln('');
$output->writeln('<info>Previous: ' . get_class($t->getPrevious()) . ': ' . $t->getPrevious()->getMessage() . '</info>');
$this->printThrowable($output, $t->getPrevious());
} }
} }
} }

View File

@ -236,6 +236,7 @@ class Setup {
} catch (\OC\HintException $e) { } catch (\OC\HintException $e) {
$errors[] = [ $errors[] = [
'error' => $e->getMessage(), 'error' => $e->getMessage(),
'exception' => $e,
'hint' => $e->getHint(), 'hint' => $e->getHint(),
]; ];
$htAccessWorking = false; $htAccessWorking = false;
@ -360,12 +361,14 @@ class Setup {
} catch (\OC\DatabaseSetupException $e) { } catch (\OC\DatabaseSetupException $e) {
$error[] = [ $error[] = [
'error' => $e->getMessage(), 'error' => $e->getMessage(),
'exception' => $e,
'hint' => $e->getHint(), 'hint' => $e->getHint(),
]; ];
return $error; return $error;
} catch (Exception $e) { } catch (Exception $e) {
$error[] = [ $error[] = [
'error' => 'Error while trying to create admin user: ' . $e->getMessage(), 'error' => 'Error while trying to create admin user: ' . $e->getMessage(),
'exception' => $e,
'hint' => '', 'hint' => '',
]; ];
return $error; return $error;
@ -376,6 +379,7 @@ class Setup {
} catch (Exception $e) { } catch (Exception $e) {
$error[] = [ $error[] = [
'error' => 'Error while trying to initialise the database: ' . $e->getMessage(), 'error' => 'Error while trying to initialise the database: ' . $e->getMessage(),
'exception' => $e,
'hint' => '', 'hint' => '',
]; ];
return $error; return $error;