mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
Catch unhandled exceptions in index.php
Summary: When there is an exception in `index.php` then we currently get only blank screen. Print it instead. Test Plan: Thrown exceptions on several places of `index.php` and controller, got best results. Reviewers: epriestley, btrahan Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D3619
This commit is contained in:
parent
58206a146f
commit
4a2bcc06fe
1 changed files with 141 additions and 136 deletions
|
@ -109,18 +109,14 @@ try {
|
||||||
|
|
||||||
PhutilErrorHandler::initialize();
|
PhutilErrorHandler::initialize();
|
||||||
|
|
||||||
} catch (Exception $ex) {
|
PhutilErrorHandler::setErrorListener(
|
||||||
phabricator_fatal("[Initialization Exception] ".$ex->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
PhutilErrorHandler::setErrorListener(
|
|
||||||
array('DarkConsoleErrorLogPluginAPI', 'handleErrors'));
|
array('DarkConsoleErrorLogPluginAPI', 'handleErrors'));
|
||||||
|
|
||||||
foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) {
|
foreach (PhabricatorEnv::getEnvConfig('load-libraries') as $library) {
|
||||||
phutil_load_library($library);
|
phutil_load_library($library);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PhabricatorEnv::getEnvConfig('phabricator.setup')) {
|
if (PhabricatorEnv::getEnvConfig('phabricator.setup')) {
|
||||||
try {
|
try {
|
||||||
PhabricatorSetup::runSetup();
|
PhabricatorSetup::runSetup();
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
|
@ -128,50 +124,50 @@ if (PhabricatorEnv::getEnvConfig('phabricator.setup')) {
|
||||||
echo $ex;
|
echo $ex;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
phabricator_detect_bad_base_uri();
|
phabricator_detect_bad_base_uri();
|
||||||
|
|
||||||
$translation = PhabricatorEnv::newObjectFromConfig('translation.provider');
|
$translation = PhabricatorEnv::newObjectFromConfig('translation.provider');
|
||||||
PhutilTranslator::getInstance()
|
PhutilTranslator::getInstance()
|
||||||
->setLanguage($translation->getLanguage())
|
->setLanguage($translation->getLanguage())
|
||||||
->addTranslations($translation->getTranslations());
|
->addTranslations($translation->getTranslations());
|
||||||
|
|
||||||
$host = $_SERVER['HTTP_HOST'];
|
$host = $_SERVER['HTTP_HOST'];
|
||||||
$path = $_REQUEST['__path__'];
|
$path = $_REQUEST['__path__'];
|
||||||
|
|
||||||
switch ($host) {
|
switch ($host) {
|
||||||
default:
|
default:
|
||||||
$config_key = 'aphront.default-application-configuration-class';
|
$config_key = 'aphront.default-application-configuration-class';
|
||||||
$application = PhabricatorEnv::newObjectFromConfig($config_key);
|
$application = PhabricatorEnv::newObjectFromConfig($config_key);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$application->setHost($host);
|
$application->setHost($host);
|
||||||
$application->setPath($path);
|
$application->setPath($path);
|
||||||
$application->willBuildRequest();
|
$application->willBuildRequest();
|
||||||
$request = $application->buildRequest();
|
$request = $application->buildRequest();
|
||||||
|
|
||||||
$write_guard = new AphrontWriteGuard(array($request, 'validateCSRF'));
|
$write_guard = new AphrontWriteGuard(array($request, 'validateCSRF'));
|
||||||
PhabricatorEventEngine::initialize();
|
PhabricatorEventEngine::initialize();
|
||||||
|
|
||||||
$application->setRequest($request);
|
$application->setRequest($request);
|
||||||
list($controller, $uri_data) = $application->buildController();
|
list($controller, $uri_data) = $application->buildController();
|
||||||
|
|
||||||
if ($access_log) {
|
if ($access_log) {
|
||||||
$access_log->setData(
|
$access_log->setData(
|
||||||
array(
|
array(
|
||||||
'U' => (string)$request->getRequestURI()->getPath(),
|
'U' => (string)$request->getRequestURI()->getPath(),
|
||||||
'C' => get_class($controller),
|
'C' => get_class($controller),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If execution throws an exception and then trying to render that exception
|
// If execution throws an exception and then trying to render that exception
|
||||||
// throws another exception, we want to show the original exception, as it is
|
// throws another exception, we want to show the original exception, as it is
|
||||||
// likely the root cause of the rendering exception.
|
// likely the root cause of the rendering exception.
|
||||||
$original_exception = null;
|
$original_exception = null;
|
||||||
try {
|
try {
|
||||||
$response = $controller->willBeginExecution();
|
$response = $controller->willBeginExecution();
|
||||||
|
|
||||||
if ($access_log) {
|
if ($access_log) {
|
||||||
|
@ -187,20 +183,20 @@ try {
|
||||||
$controller->willProcessRequest($uri_data);
|
$controller->willProcessRequest($uri_data);
|
||||||
$response = $controller->processRequest();
|
$response = $controller->processRequest();
|
||||||
}
|
}
|
||||||
} catch (AphrontRedirectException $ex) {
|
} catch (AphrontRedirectException $ex) {
|
||||||
$response = id(new AphrontRedirectResponse())
|
$response = id(new AphrontRedirectResponse())
|
||||||
->setURI($ex->getURI());
|
->setURI($ex->getURI());
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
$original_exception = $ex;
|
$original_exception = $ex;
|
||||||
$response = $application->handleException($ex);
|
$response = $application->handleException($ex);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$response = $controller->didProcessRequest($response);
|
$response = $controller->didProcessRequest($response);
|
||||||
$response = $application->willSendResponse($response, $controller);
|
$response = $application->willSendResponse($response, $controller);
|
||||||
$response->setRequest($request);
|
$response->setRequest($request);
|
||||||
$response_string = $response->buildResponseString();
|
$response_string = $response->buildResponseString();
|
||||||
} catch (Exception $ex) {
|
} catch (Exception $ex) {
|
||||||
$write_guard->dispose();
|
$write_guard->dispose();
|
||||||
if ($access_log) {
|
if ($access_log) {
|
||||||
$access_log->write();
|
$access_log->write();
|
||||||
|
@ -214,32 +210,32 @@ try {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
phabricator_fatal('[Rendering Exception] '.$ex->getMessage());
|
phabricator_fatal('[Rendering Exception] '.$ex->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$write_guard->dispose();
|
$write_guard->dispose();
|
||||||
|
|
||||||
// TODO: Share the $sink->writeResponse() pathway here?
|
// TODO: Share the $sink->writeResponse() pathway here?
|
||||||
|
|
||||||
$sink = new AphrontPHPHTTPSink();
|
$sink = new AphrontPHPHTTPSink();
|
||||||
$sink->writeHTTPStatus($response->getHTTPResponseCode());
|
$sink->writeHTTPStatus($response->getHTTPResponseCode());
|
||||||
|
|
||||||
$headers = $response->getCacheHeaders();
|
$headers = $response->getCacheHeaders();
|
||||||
$headers = array_merge($headers, $response->getHeaders());
|
$headers = array_merge($headers, $response->getHeaders());
|
||||||
|
|
||||||
$sink->writeHeaders($headers);
|
$sink->writeHeaders($headers);
|
||||||
|
|
||||||
$sink->writeData($response_string);
|
$sink->writeData($response_string);
|
||||||
|
|
||||||
if ($access_log) {
|
if ($access_log) {
|
||||||
$access_log->setData(
|
$access_log->setData(
|
||||||
array(
|
array(
|
||||||
'c' => $response->getHTTPResponseCode(),
|
'c' => $response->getHTTPResponseCode(),
|
||||||
'T' => (int)(1000000 * (microtime(true) - $__start__)),
|
'T' => (int)(1000000 * (microtime(true) - $__start__)),
|
||||||
));
|
));
|
||||||
$access_log->write();
|
$access_log->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DarkConsoleXHProfPluginAPI::isProfilerRequested()) {
|
if (DarkConsoleXHProfPluginAPI::isProfilerRequested()) {
|
||||||
$profile = DarkConsoleXHProfPluginAPI::stopProfiler();
|
$profile = DarkConsoleXHProfPluginAPI::stopProfiler();
|
||||||
$profile_sample = id(new PhabricatorXHProfSample())
|
$profile_sample = id(new PhabricatorXHProfSample())
|
||||||
->setFilePHID($profile);
|
->setFilePHID($profile);
|
||||||
|
@ -257,8 +253,13 @@ if (DarkConsoleXHProfPluginAPI::isProfilerRequested()) {
|
||||||
->setUserPHID($request->getUser()->getPHID());
|
->setUserPHID($request->getUser()->getPHID());
|
||||||
}
|
}
|
||||||
$profile_sample->save();
|
$profile_sample->save();
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
phabricator_fatal("[Exception] ".$ex->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group aphront
|
* @group aphront
|
||||||
*/
|
*/
|
||||||
|
@ -352,11 +353,15 @@ function phabricator_fatal($msg) {
|
||||||
|
|
||||||
global $access_log;
|
global $access_log;
|
||||||
if ($access_log) {
|
if ($access_log) {
|
||||||
|
try {
|
||||||
$access_log->setData(
|
$access_log->setData(
|
||||||
array(
|
array(
|
||||||
'c' => 500,
|
'c' => 500,
|
||||||
));
|
));
|
||||||
$access_log->write();
|
$access_log->write();
|
||||||
|
} catch (Exception $ex) {
|
||||||
|
$msg .= "\nMoreover unable to write to access log.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
header(
|
header(
|
||||||
|
|
Loading…
Reference in a new issue