From f1921364d692a521c5bf5860ce453bae3f9facae Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Thu, 7 Jan 2021 20:04:04 +0100 Subject: [PATCH 1/2] 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 +++++++++++++++++++--- lib/private/Setup.php | 4 ++++ 2 files changed, 23 insertions(+), 3 deletions(-) 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()); + } + } } diff --git a/lib/private/Setup.php b/lib/private/Setup.php index 873e82e55de..98cf11e3a87 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -236,6 +236,7 @@ class Setup { } catch (\OC\HintException $e) { $errors[] = [ 'error' => $e->getMessage(), + 'exception' => $e, 'hint' => $e->getHint(), ]; $htAccessWorking = false; @@ -360,12 +361,14 @@ class Setup { } catch (\OC\DatabaseSetupException $e) { $error[] = [ 'error' => $e->getMessage(), + 'exception' => $e, 'hint' => $e->getHint(), ]; return $error; } catch (Exception $e) { $error[] = [ 'error' => 'Error while trying to create admin user: ' . $e->getMessage(), + 'exception' => $e, 'hint' => '', ]; return $error; @@ -376,6 +379,7 @@ class Setup { } catch (Exception $e) { $error[] = [ 'error' => 'Error while trying to initialise the database: ' . $e->getMessage(), + 'exception' => $e, 'hint' => '', ]; return $error; From d0ac76a77c820d065f7b4af5238e5d11ec66253b Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 7 Jan 2021 21:04:11 +0100 Subject: [PATCH 2/2] Add more previous exceptions to database setup code Signed-off-by: Morris Jobke --- core/Command/Maintenance/Install.php | 1 + lib/private/Setup/MySQL.php | 2 +- lib/private/Setup/OCI.php | 4 ++-- lib/private/Setup/PostgreSQL.php | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php index ed1aeeff922..fc219e79bcd 100644 --- a/core/Command/Maintenance/Install.php +++ b/core/Command/Maintenance/Install.php @@ -218,6 +218,7 @@ class Install extends Command { private function printThrowable(OutputInterface $output, Throwable $t): void { $output->write('Trace: ' . $t->getTraceAsString() . ''); + $output->writeln(''); if ($t->getPrevious() !== null) { $output->writeln(''); $output->writeln('Previous: ' . get_class($t->getPrevious()) . ': ' . $t->getPrevious()->getMessage() . ''); diff --git a/lib/private/Setup/MySQL.php b/lib/private/Setup/MySQL.php index 54542de72bf..966c97edf55 100644 --- a/lib/private/Setup/MySQL.php +++ b/lib/private/Setup/MySQL.php @@ -66,7 +66,7 @@ class MySQL extends AbstractDatabase { } catch (\Exception $e) { $this->logger->logException($e); throw new \OC\DatabaseSetupException($this->trans->t('MySQL username and/or password not valid'), - $this->trans->t('You need to enter details of an existing account.')); + $this->trans->t('You need to enter details of an existing account.'), 0, $e); } } diff --git a/lib/private/Setup/OCI.php b/lib/private/Setup/OCI.php index 1d7fe27e8b8..ed05e0bf14c 100644 --- a/lib/private/Setup/OCI.php +++ b/lib/private/Setup/OCI.php @@ -74,14 +74,14 @@ class OCI extends AbstractDatabase { . ' ORACLE_SID=' . getenv('ORACLE_SID') . ' LD_LIBRARY_PATH=' . getenv('LD_LIBRARY_PATH') . ' NLS_LANG=' . getenv('NLS_LANG') - . ' tnsnames.ora is ' . (is_readable(getenv('ORACLE_HOME') . '/network/admin/tnsnames.ora') ? '' : 'not ') . 'readable'); + . ' tnsnames.ora is ' . (is_readable(getenv('ORACLE_HOME') . '/network/admin/tnsnames.ora') ? '' : 'not ') . 'readable', 0, $e); } throw new \OC\DatabaseSetupException($this->trans->t('Oracle username and/or password not valid'), 'Check environment: ORACLE_HOME=' . getenv('ORACLE_HOME') . ' ORACLE_SID=' . getenv('ORACLE_SID') . ' LD_LIBRARY_PATH=' . getenv('LD_LIBRARY_PATH') . ' NLS_LANG=' . getenv('NLS_LANG') - . ' tnsnames.ora is ' . (is_readable(getenv('ORACLE_HOME') . '/network/admin/tnsnames.ora') ? '' : 'not ') . 'readable'); + . ' tnsnames.ora is ' . (is_readable(getenv('ORACLE_HOME') . '/network/admin/tnsnames.ora') ? '' : 'not ') . 'readable', 0, $e); } $this->config->setValues([ diff --git a/lib/private/Setup/PostgreSQL.php b/lib/private/Setup/PostgreSQL.php index 3d7a0b2a4b1..1f0b7b8f894 100644 --- a/lib/private/Setup/PostgreSQL.php +++ b/lib/private/Setup/PostgreSQL.php @@ -99,7 +99,7 @@ class PostgreSQL extends AbstractDatabase { } catch (\Exception $e) { $this->logger->logException($e); throw new \OC\DatabaseSetupException($this->trans->t('PostgreSQL username and/or password not valid'), - $this->trans->t('You need to enter details of an existing account.')); + $this->trans->t('You need to enter details of an existing account.'), 0, $e); } }