Skip to content
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

Print an exception trace for setup exceptions #25021

Merged
merged 2 commits into from
Jan 8, 2021
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
23 changes: 20 additions & 3 deletions core/Command/Maintenance/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
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 {

Expand Down Expand Up @@ -201,11 +203,26 @@ protected function validateInput(InputInterface $input, OutputInterface $output,
protected function printErrors(OutputInterface $output, $errors) {
foreach ($errors as $error) {
if (is_array($error)) {
$output->writeln('<error>' . (string)$error['error'] . '</error>');
$output->writeln('<info> -> ' . (string)$error['hint'] . '</info>');
$output->writeln('<error>' . $error['error'] . '</error>');
if (isset($error['hint']) && !empty($error['hint'])) {
$output->writeln('<info> -> ' . $error['hint'] . '</info>');
}
if (isset($error['exception']) && $error['exception'] instanceof Throwable) {
$this->printThrowable($output, $error['exception']);
}
} else {
$output->writeln('<error>' . (string)$error . '</error>');
$output->writeln('<error>' . $error . '</error>');
}
}
}

private function printThrowable(OutputInterface $output, Throwable $t): void {
$output->write('<info>Trace: ' . $t->getTraceAsString() . '</info>');
$output->writeln('');
if ($t->getPrevious() !== null) {
$output->writeln('');
$output->writeln('<info>Previous: ' . get_class($t->getPrevious()) . ': ' . $t->getPrevious()->getMessage() . '</info>');
$this->printThrowable($output, $t->getPrevious());
}
}
}
4 changes: 4 additions & 0 deletions lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ public function getSystemInfo($allowAllDatabases = false) {
} catch (\OC\HintException $e) {
$errors[] = [
'error' => $e->getMessage(),
'exception' => $e,
'hint' => $e->getHint(),
];
$htAccessWorking = false;
Expand Down Expand Up @@ -360,12 +361,14 @@ public function install($options) {
} 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;
Expand All @@ -376,6 +379,7 @@ public function install($options) {
} catch (Exception $e) {
$error[] = [
'error' => 'Error while trying to initialise the database: ' . $e->getMessage(),
'exception' => $e,
'hint' => '',
];
return $error;
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Setup/MySQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function setupDatabase($username) {
} 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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/private/Setup/OCI.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,14 @@ public function setupDatabase($username) {
. ' 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([
Expand Down
2 changes: 1 addition & 1 deletion lib/private/Setup/PostgreSQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public function setupDatabase($username) {
} 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);
}
}

Expand Down