diff options
author | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-04-20 22:41:02 +0200 |
---|---|---|
committer | Thomas Müller <DeepDiver1975@users.noreply.github.com> | 2016-04-20 22:41:02 +0200 |
commit | a061ef75ead3d5eb9fa5e713301b7452b3b12b73 (patch) | |
tree | ea758fc9cbf054e513e4358b63fc3b3a3a6d30b0 | |
parent | 7e2a1656f9e9fbfda7835bf448a7c63100ab2378 (diff) | |
parent | 7fea9974b7b3d0177678c5b577e10c930c13eb1e (diff) | |
download | nextcloud-server-a061ef75ead3d5eb9fa5e713301b7452b3b12b73.tar.gz nextcloud-server-a061ef75ead3d5eb9fa5e713301b7452b3b12b73.zip |
Merge pull request #24127 from owncloud/handle-app-loading-error
Handle app loading error
-rw-r--r-- | console.php | 2 | ||||
-rw-r--r-- | cron.php | 2 | ||||
-rw-r--r-- | index.php | 8 | ||||
-rw-r--r-- | lib/private/app.php | 12 | ||||
-rw-r--r-- | lib/private/log.php | 4 | ||||
-rw-r--r-- | lib/private/template.php | 2 | ||||
-rw-r--r-- | lib/public/ilogger.php | 4 | ||||
-rw-r--r-- | public.php | 16 | ||||
-rw-r--r-- | remote.php | 8 |
9 files changed, 40 insertions, 18 deletions
diff --git a/console.php b/console.php index 9d2271db9f2..559c1778f1d 100644 --- a/console.php +++ b/console.php @@ -95,4 +95,6 @@ try { $application->run(); } catch (Exception $ex) { exceptionHandler($ex); +} catch (Error $ex) { + exceptionHandler($ex); } @@ -175,4 +175,6 @@ try { } catch (Exception $ex) { \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); +} catch (Error $ex) { + \OCP\Util::writeLog('cron', $ex->getMessage(), \OCP\Util::FATAL); } diff --git a/index.php b/index.php index f3bf699f3c1..2acf81ab6d7 100644 --- a/index.php +++ b/index.php @@ -39,7 +39,7 @@ try { OC::handleRequest(); } catch(\OC\ServiceUnavailableException $ex) { - \OCP\Util::logException('index', $ex); + \OC::$server->getLogger()->logException($ex, ['app' => 'index']); //show the user a detailed error page OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); @@ -48,9 +48,13 @@ try { OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); OC_Template::printErrorPage($ex->getMessage(), $ex->getHint()); } catch (Exception $ex) { - \OCP\Util::logException('index', $ex); + \OC::$server->getLogger()->logException($ex, ['app' => 'index']); //show the user a detailed error page OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); OC_Template::printExceptionErrorPage($ex); +} catch (Error $ex) { + \OC::$server->getLogger()->logException($ex, ['app' => 'index']); + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); + OC_Template::printExceptionErrorPage($ex); } diff --git a/lib/private/app.php b/lib/private/app.php index 05d220f7d38..8a8b97d2cd4 100644 --- a/lib/private/app.php +++ b/lib/private/app.php @@ -159,8 +159,16 @@ class OC_App { * @param string $app app name */ private static function requireAppFile($app) { - // encapsulated here to avoid variable scope conflicts - require_once $app . '/appinfo/app.php'; + try { + // encapsulated here to avoid variable scope conflicts + require_once $app . '/appinfo/app.php'; + } catch (Error $ex) { + \OC::$server->getLogger()->logException($ex); + $blacklist = \OC::$server->getAppManager()->getAlwaysEnabledApps(); + if (!in_array($app, $blacklist)) { + self::disable($app); + } + } } /** diff --git a/lib/private/log.php b/lib/private/log.php index 9a2a2da906e..bbdad9cf166 100644 --- a/lib/private/log.php +++ b/lib/private/log.php @@ -270,12 +270,12 @@ class Log implements ILogger { /** * Logs an exception very detailed * - * @param \Exception $exception + * @param \Exception | \Throwable $exception * @param array $context * @return void * @since 8.2.0 */ - public function logException(\Exception $exception, array $context = array()) { + public function logException($exception, array $context = array()) { $exception = array( 'Exception' => get_class($exception), 'Message' => $exception->getMessage(), diff --git a/lib/private/template.php b/lib/private/template.php index c6542356fac..73725529702 100644 --- a/lib/private/template.php +++ b/lib/private/template.php @@ -333,7 +333,7 @@ class OC_Template extends \OC\Template\Base { /** * print error page using Exception details - * @param Exception $exception + * @param Exception | Throwable $exception */ public static function printExceptionErrorPage($exception, $fetchPage = false) { try { diff --git a/lib/public/ilogger.php b/lib/public/ilogger.php index 6a4163875a9..fa947612fcd 100644 --- a/lib/public/ilogger.php +++ b/lib/public/ilogger.php @@ -135,10 +135,10 @@ interface ILogger { * ]); * </code> * - * @param \Exception $exception + * @param \Exception | \Throwable $exception * @param array $context * @return void * @since 8.2.0 */ - public function logException(\Exception $exception, array $context = array()); + public function logException($exception, array $context = array()); } diff --git a/public.php b/public.php index 65257f1a46e..c4d96c06496 100644 --- a/public.php +++ b/public.php @@ -49,7 +49,7 @@ try { $pathInfo = trim($pathInfo, '/'); list($service) = explode('/', $pathInfo); } - $file = OCP\CONFIG::getAppValue('core', 'public_' . strip_tags($service)); + $file = OCP\Config::getAppValue('core', 'public_' . strip_tags($service)); if (is_null($file)) { header('HTTP/1.0 404 Not Found'); exit; @@ -73,14 +73,18 @@ try { require_once OC_App::getAppPath($app) . '/' . $parts[1]; -} catch (\OC\ServiceUnavailableException $ex) { +} catch (Exception $ex) { + if ($ex instanceof \OC\ServiceUnavailableException) { + OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); + } else { + OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); + } //show the user a detailed error page - OC_Response::setStatus(OC_Response::STATUS_SERVICE_UNAVAILABLE); - \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL); + \OC::$server->getLogger()->logException($ex, ['app' => 'public']); OC_Template::printExceptionErrorPage($ex); -} catch (Exception $ex) { +} catch (Error $ex) { //show the user a detailed error page OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); - \OCP\Util::writeLog('remote', $ex->getMessage(), \OCP\Util::FATAL); + \OC::$server->getLogger()->logException($ex, ['app' => 'public']); OC_Template::printExceptionErrorPage($ex); } diff --git a/remote.php b/remote.php index 814286860af..991ca0d2302 100644 --- a/remote.php +++ b/remote.php @@ -40,9 +40,9 @@ class RemoteException extends Exception { } /** - * @param Exception $e + * @param Exception | Error $e */ -function handleException(Exception $e) { +function handleException($e) { $request = \OC::$server->getRequest(); // in case the request content type is text/xml - we assume it's a WebDAV request $isXmlContentType = strpos($request->getHeader('Content-Type'), 'text/xml'); @@ -77,7 +77,7 @@ function handleException(Exception $e) { OC_Response::setStatus($e->getCode()); OC_Template::printErrorPage($e->getMessage()); } else { - \OCP\Util::writeLog('remote', $e->getMessage(), \OCP\Util::FATAL); + \OC::$server->getLogger()->logException($e, ['app' => 'remote']); OC_Response::setStatus($statusCode); OC_Template::printExceptionErrorPage($e); } @@ -165,4 +165,6 @@ try { } catch (Exception $ex) { handleException($ex); +} catch (Error $e) { + handleException($ex); } |