Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / console / plugin / errorlog / DarkConsoleErrorLogPluginAPI.php
blobbc276da0da2c43323885514a9d2cc49663ca3768
1 <?php
3 final class DarkConsoleErrorLogPluginAPI extends Phobject {
5 private static $errors = array();
7 private static $discardMode = false;
9 public static function registerErrorHandler() {
10 // NOTE: This forces PhutilReadableSerializer to load, so that we are
11 // able to handle errors which fire from inside autoloaders (PHP will not
12 // reenter autoloaders).
13 PhutilReadableSerializer::printableValue(null);
14 PhutilErrorHandler::setErrorListener(
15 array(__CLASS__, 'handleErrors'));
18 public static function enableDiscardMode() {
19 self::$discardMode = true;
22 public static function disableDiscardMode() {
23 self::$discardMode = false;
26 public static function getErrors() {
27 return self::$errors;
30 public static function handleErrors($event, $value, $metadata) {
31 if (self::$discardMode) {
32 return;
35 switch ($event) {
36 case PhutilErrorHandler::EXCEPTION:
37 // $value is of type Exception
38 self::$errors[] = array(
39 'details' => $value->getMessage(),
40 'event' => $event,
41 'file' => $value->getFile(),
42 'line' => $value->getLine(),
43 'str' => $value->getMessage(),
44 'trace' => $metadata['trace'],
46 break;
47 case PhutilErrorHandler::ERROR:
48 // $value is a simple string
49 self::$errors[] = array(
50 'details' => $value,
51 'event' => $event,
52 'file' => $metadata['file'],
53 'line' => $metadata['line'],
54 'str' => $value,
55 'trace' => $metadata['trace'],
57 break;
58 case PhutilErrorHandler::PHLOG:
59 // $value can be anything
60 self::$errors[] = array(
61 'details' => PhutilReadableSerializer::printShallow($value, 3),
62 'event' => $event,
63 'file' => $metadata['file'],
64 'line' => $metadata['line'],
65 'str' => PhutilReadableSerializer::printShort($value),
66 'trace' => $metadata['trace'],
68 break;
69 default:
70 error_log(pht('Unknown event: %s', $event));
71 break;