@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Improve exception reporting behavior for core exceptions

Summary:
See <https://github.com/facebook/phabricator/issues/487>. If an exception is thrown too high in the stack for the main exception handling to deal with it, we currently never report a stack trace. Instead:

- Always report a stack trace to the error log.
- With developer mode, also report a stack trace to the screen.

Test Plan: Added a high-level `throw` and hit both cases. Got traces in the log and traces-under-developer-mode on screen.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D8022

+58 -4
+47 -2
support/PhabricatorStartup.php
··· 198 198 199 199 200 200 /** 201 + * Fatal the request completely in response to an exception, sending a plain 202 + * text message to the client. Calls @{method:didFatal} internally. 203 + * 204 + * @param string Brief description of the exception context, like 205 + * `"Rendering Exception"`. 206 + * @param Exception The exception itself. 207 + * @param bool True if it's okay to show the exception's stack trace 208 + * to the user. The trace will always be logged. 209 + * @return exit This method **does not return**. 210 + * 201 211 * @task apocalypse 202 212 */ 203 - public static function didFatal($message) { 213 + public static function didEncounterFatalException( 214 + $note, 215 + Exception $ex, 216 + $show_trace) { 217 + 218 + $message = '['.$note.'/'.get_class($ex).'] '.$ex->getMessage(); 219 + 220 + $full_message = $message; 221 + $full_message .= "\n\n"; 222 + $full_message .= $ex->getTraceAsString(); 223 + 224 + if ($show_trace) { 225 + $message = $full_message; 226 + } 227 + 228 + self::didFatal($message, $full_message); 229 + } 230 + 231 + 232 + /** 233 + * Fatal the request completely, sending a plain text message to the client. 234 + * 235 + * @param string Plain text message to send to the client. 236 + * @param string Plain text message to send to the error log. If not 237 + * provided, the client message is used. You can pass a more 238 + * detailed message here (e.g., with stack traces) to avoid 239 + * showing it to users. 240 + * @return exit This method **does not return**. 241 + * 242 + * @task apocalypse 243 + */ 244 + public static function didFatal($message, $log_message = null) { 245 + if ($log_message === null) { 246 + $log_message = $message; 247 + } 248 + 204 249 self::endOutputCapture(); 205 250 $access_log = self::getGlobal('log.access'); 206 251 ··· 219 264 $replace = true, 220 265 $http_error = 500); 221 266 222 - error_log($message); 267 + error_log($log_message); 223 268 echo $message; 224 269 225 270 exit(1);
+11 -2
webroot/index.php
··· 3 3 require_once dirname(dirname(__FILE__)).'/support/PhabricatorStartup.php'; 4 4 PhabricatorStartup::didStartup(); 5 5 6 + $show_unexpected_traces = false; 6 7 try { 7 8 PhabricatorStartup::loadCoreLibraries(); 8 9 9 10 PhabricatorEnv::initializeWebEnvironment(); 11 + $show_unexpected_traces = PhabricatorEnv::getEnvConfig( 12 + 'phabricator.developer-mode'); 10 13 11 14 // This is the earliest we can get away with this, we need env config first. 12 15 PhabricatorAccessLog::init(); ··· 124 127 $ex, 125 128 )); 126 129 } 127 - PhabricatorStartup::didFatal('[Rendering Exception] '.$ex->getMessage()); 130 + PhabricatorStartup::didEncounterFatalException( 131 + 'Rendering Exception', 132 + $ex, 133 + $show_unexpected_traces); 128 134 } 129 135 130 136 $write_guard->dispose(); ··· 137 143 138 144 DarkConsoleXHProfPluginAPI::saveProfilerSample($access_log); 139 145 } catch (Exception $ex) { 140 - PhabricatorStartup::didFatal("[Exception] ".$ex->getMessage()); 146 + PhabricatorStartup::didEncounterFatalException( 147 + 'Core Exception', 148 + $ex, 149 + $show_unexpected_traces); 141 150 } 142 151