Changeset View
Changeset View
Standalone View
Standalone View
src/error/PhutilErrorHandler.php
| Show First 20 Lines • Show All 189 Lines • ▼ Show 20 Lines | if ((error_reporting() & $num) == 0) { | ||||
| // Respect the use of "@" to silence warnings: if this error was | // Respect the use of "@" to silence warnings: if this error was | ||||
| // emitted from a context where "@" was in effect, the | // emitted from a context where "@" was in effect, the | ||||
| // value returned by error_reporting() will be 0. This is the | // value returned by error_reporting() will be 0. This is the | ||||
| // recommended way to check for this, see set_error_handler() docs | // recommended way to check for this, see set_error_handler() docs | ||||
| // on php.net. | // on php.net. | ||||
| return false; | return false; | ||||
| } | } | ||||
| // See T13499. If this is a user error arising from "trigger_error()" or | |||||
| // similar, route it through normal error handling: this is probably the | |||||
| // best match to authorial intent, since the code could choose to throw | |||||
| // an exception instead if it wanted that behavior. Phabricator does not | |||||
| // use "trigger_error()" so we never normally expect to reach this | |||||
| // block in first-party code. | |||||
| if (($num === E_USER_ERROR) || | |||||
| ($num === E_USER_WARNING) || | |||||
| ($num === E_USER_NOTICE)) { | |||||
| $trace = debug_backtrace(); | |||||
| array_shift($trace); | |||||
| self::dispatchErrorMessage( | |||||
| self::ERROR, | |||||
| $str, | |||||
| array( | |||||
| 'file' => $file, | |||||
| 'line' => $line, | |||||
| 'context' => $ctx, | |||||
| 'error_code' => $num, | |||||
| 'trace' => $trace, | |||||
| )); | |||||
| return; | |||||
| } | |||||
| // Convert typehint failures into exceptions. | // Convert typehint failures into exceptions. | ||||
| if (preg_match('/^Argument (\d+) passed to (\S+) must be/', $str)) { | if (preg_match('/^Argument (\d+) passed to (\S+) must be/', $str)) { | ||||
| throw new InvalidArgumentException($str); | throw new InvalidArgumentException($str); | ||||
| } | } | ||||
| // Convert other E_RECOVERABLE_ERRORs into generic runtime exceptions. | // Convert other E_RECOVERABLE_ERRORs into generic runtime exceptions. | ||||
| if ($num == E_RECOVERABLE_ERROR) { | if ($num == E_RECOVERABLE_ERROR) { | ||||
| throw new RuntimeException($str); | throw new RuntimeException($str); | ||||
| Show All 10 Lines | public static function handleError($num, $str, $file, $line, $ctx) { | ||||
| } | } | ||||
| // Convert undefined constants into exceptions. Usually this means there | // Convert undefined constants into exceptions. Usually this means there | ||||
| // is a missing `$` and the program is horribly broken. | // is a missing `$` and the program is horribly broken. | ||||
| if (preg_match('/^Use of undefined constant /', $str)) { | if (preg_match('/^Use of undefined constant /', $str)) { | ||||
| throw new RuntimeException($str); | throw new RuntimeException($str); | ||||
| } | } | ||||
| $trace = debug_backtrace(); | // Convert undefined indexes into exceptions. | ||||
| array_shift($trace); | if (preg_match('/^Undefined index: /', $str)) { | ||||
| self::dispatchErrorMessage( | throw new RuntimeException($str); | ||||
| self::ERROR, | } | ||||
| $str, | |||||
| array( | // Convert undefined offsets into exceptions. | ||||
| 'file' => $file, | if (preg_match('/^Undefined offset: /', $str)) { | ||||
| 'line' => $line, | throw new RuntimeException($str); | ||||
| 'context' => $ctx, | } | ||||
| 'error_code' => $num, | |||||
| 'trace' => $trace, | // See T13499. Convert all other runtime errors not handled in a more | ||||
| )); | // specific way into runtime exceptions. | ||||
| throw new RuntimeException($str); | |||||
| } | } | ||||
| /** | /** | ||||
| * Handles PHP exceptions and dispatches them forward. This is a callback for | * Handles PHP exceptions and dispatches them forward. This is a callback for | ||||
| * ##set_exception_handler()##. You should not call this function directly; | * ##set_exception_handler()##. You should not call this function directly; | ||||
| * to print exceptions, pass the exception object to @{function:phlog}. | * to print exceptions, pass the exception object to @{function:phlog}. | ||||
| * | * | ||||
| * @param Exception|Throwable Uncaught exception object. | * @param Exception|Throwable Uncaught exception object. | ||||
| ▲ Show 20 Lines • Show All 352 Lines • Show Last 20 Lines | |||||