mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-21 22:32:41 +01:00
Make it easier to use print_r() debugging
Summary: The fixed-position side nav background thing tends to make looking at print_r() output hard. Also, it breaks Ajax, etc. - Loudly call out unexpected output on normal pages, to catch extra spaces before `<?php`, etc. - Display unexpected output in an attractive panel on normal pages. - Log unexpected output instead of breaking Ajax. Test Plan: {F32267} Also triggered various fatals and verified they still show the right messages (no blank pages). Reviewers: vrana, btrahan, chad Reviewed By: btrahan CC: aran Differential Revision: https://secure.phabricator.com/D4892
This commit is contained in:
parent
1e74c05ac6
commit
f1a36cf3c8
2 changed files with 39 additions and 1 deletions
|
@ -17,6 +17,7 @@ final class PhabricatorStartup {
|
|||
|
||||
private static $startTime;
|
||||
private static $globals = array();
|
||||
private static $capturingOutput;
|
||||
|
||||
|
||||
/* -( Accessing Request Information )-------------------------------------- */
|
||||
|
@ -78,6 +79,8 @@ final class PhabricatorStartup {
|
|||
self::verifyRewriteRules();
|
||||
|
||||
self::detectPostMaxSizeTriggered();
|
||||
|
||||
self::beginOutputCapture();
|
||||
}
|
||||
|
||||
|
||||
|
@ -149,6 +152,26 @@ final class PhabricatorStartup {
|
|||
phutil_load_library($phabricator_root.'/src');
|
||||
}
|
||||
|
||||
/* -( Output Capture )----------------------------------------------------- */
|
||||
|
||||
|
||||
public static function beginOutputCapture() {
|
||||
if (self::$capturingOutput) {
|
||||
self::didFatal("Already capturing output!");
|
||||
}
|
||||
self::$capturingOutput = true;
|
||||
ob_start();
|
||||
}
|
||||
|
||||
|
||||
public static function endOutputCapture() {
|
||||
if (!self::$capturingOutput) {
|
||||
return null;
|
||||
}
|
||||
self::$capturingOutput = false;
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
|
||||
/* -( In Case of Apocalypse )---------------------------------------------- */
|
||||
|
||||
|
@ -157,6 +180,7 @@ final class PhabricatorStartup {
|
|||
* @task apocalypse
|
||||
*/
|
||||
public static function didFatal($message) {
|
||||
self::endOutputCapture();
|
||||
$access_log = self::getGlobal('log.access');
|
||||
|
||||
if ($access_log) {
|
||||
|
|
|
@ -30,6 +30,7 @@ try {
|
|||
|
||||
$response = PhabricatorSetupCheck::willProcessRequest();
|
||||
if ($response) {
|
||||
PhabricatorStartup::endOutputCapture();
|
||||
$sink->writeResponse($response);
|
||||
return;
|
||||
}
|
||||
|
@ -102,8 +103,21 @@ try {
|
|||
$response = $application->willSendResponse($response, $controller);
|
||||
$response->setRequest($request);
|
||||
|
||||
$sink->writeResponse($response);
|
||||
$unexpected_output = PhabricatorStartup::endOutputCapture();
|
||||
if ($unexpected_output) {
|
||||
$unexpected_output = "Unexpected output:\n\n{$unexpected_output}";
|
||||
phlog($unexpected_output);
|
||||
|
||||
if ($response instanceof AphrontWebpageResponse) {
|
||||
echo hsprintf(
|
||||
'<div style="background: #eeddff; white-space: pre-wrap;
|
||||
z-index: 200000; position: relative; padding: 8px;
|
||||
font-family: monospace;">%s</div>',
|
||||
$unexpected_output);
|
||||
}
|
||||
}
|
||||
|
||||
$sink->writeResponse($response);
|
||||
} catch (Exception $ex) {
|
||||
$write_guard->dispose();
|
||||
if ($access_log) {
|
||||
|
|
Loading…
Reference in a new issue