From e53d5b2dbe69850cb7508dfa43b9f4c03450da12 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 16 Sep 2019 19:38:13 +0200 Subject: [PATCH 1/2] Print plain error when the error page errors too Signed-off-by: Joas Schilling --- lib/base.php | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/base.php b/lib/base.php index 7812922c16..f715324739 100644 --- a/lib/base.php +++ b/lib/base.php @@ -652,30 +652,35 @@ class OC { if (!defined('OC_CONSOLE')) { $errors = OC_Util::checkServer(\OC::$server->getSystemConfig()); if (count($errors) > 0) { - if (self::$CLI) { - // Convert l10n string into regular string for usage in database - $staticErrors = []; - foreach ($errors as $error) { - echo $error['error'] . "\n"; - echo $error['hint'] . "\n\n"; - $staticErrors[] = [ - 'error' => (string)$error['error'], - 'hint' => (string)$error['hint'], - ]; - } - - try { - \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); - } catch (\Exception $e) { - echo('Writing to database failed'); - } - exit(1); - } else { + if (!self::$CLI) { http_response_code(503); OC_Util::addStyle('guest'); - OC_Template::printGuestPage('', 'error', array('errors' => $errors)); - exit; + try { + OC_Template::printGuestPage('', 'error', array('errors' => $errors)); + exit; + } catch (\Exception $e) { + // In case any error happens when showing the error page, we simply fall back to posting the text. + // This might be the case when e.g. the data directory is broken and we can not load/write SCSS to/from it. + } } + + // Convert l10n string into regular string for usage in database + $staticErrors = []; + foreach ($errors as $error) { + echo $error['error'] . "\n"; + echo $error['hint'] . "\n\n"; + $staticErrors[] = [ + 'error' => (string)$error['error'], + 'hint' => (string)$error['hint'], + ]; + } + + try { + \OC::$server->getConfig()->setAppValue('core', 'cronErrors', json_encode($staticErrors)); + } catch (\Exception $e) { + echo('Writing to database failed'); + } + exit(1); } elseif (self::$CLI && \OC::$server->getConfig()->getSystemValue('installed', false)) { \OC::$server->getConfig()->deleteAppValue('core', 'cronErrors'); } From ad7d13a87ceb5d20559808cad2c63c445ee4047c Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 16 Sep 2019 19:38:43 +0200 Subject: [PATCH 2/2] Print the error pages as error so we load less scripts and might be able to view it Signed-off-by: Joas Schilling --- lib/private/legacy/template.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/legacy/template.php b/lib/private/legacy/template.php index 6d9bf7c99f..26b1b360ad 100644 --- a/lib/private/legacy/template.php +++ b/lib/private/legacy/template.php @@ -266,7 +266,7 @@ class OC_Template extends \OC\Template\Base { * @return bool */ public static function printGuestPage( $application, $name, $parameters = array() ) { - $content = new OC_Template( $application, $name, "guest" ); + $content = new OC_Template($application, $name, $name === 'error' ? $name : 'guest'); foreach( $parameters as $key => $value ) { $content->assign( $key, $value ); }