1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +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:
epriestley 2013-02-11 11:06:59 -08:00
parent 1e74c05ac6
commit f1a36cf3c8
2 changed files with 39 additions and 1 deletions

View file

@ -17,6 +17,7 @@ final class PhabricatorStartup {
private static $startTime; private static $startTime;
private static $globals = array(); private static $globals = array();
private static $capturingOutput;
/* -( Accessing Request Information )-------------------------------------- */ /* -( Accessing Request Information )-------------------------------------- */
@ -78,6 +79,8 @@ final class PhabricatorStartup {
self::verifyRewriteRules(); self::verifyRewriteRules();
self::detectPostMaxSizeTriggered(); self::detectPostMaxSizeTriggered();
self::beginOutputCapture();
} }
@ -149,6 +152,26 @@ final class PhabricatorStartup {
phutil_load_library($phabricator_root.'/src'); 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 )---------------------------------------------- */ /* -( In Case of Apocalypse )---------------------------------------------- */
@ -157,6 +180,7 @@ final class PhabricatorStartup {
* @task apocalypse * @task apocalypse
*/ */
public static function didFatal($message) { public static function didFatal($message) {
self::endOutputCapture();
$access_log = self::getGlobal('log.access'); $access_log = self::getGlobal('log.access');
if ($access_log) { if ($access_log) {

View file

@ -30,6 +30,7 @@ try {
$response = PhabricatorSetupCheck::willProcessRequest(); $response = PhabricatorSetupCheck::willProcessRequest();
if ($response) { if ($response) {
PhabricatorStartup::endOutputCapture();
$sink->writeResponse($response); $sink->writeResponse($response);
return; return;
} }
@ -102,8 +103,21 @@ try {
$response = $application->willSendResponse($response, $controller); $response = $application->willSendResponse($response, $controller);
$response->setRequest($request); $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) { } catch (Exception $ex) {
$write_guard->dispose(); $write_guard->dispose();
if ($access_log) { if ($access_log) {