diff --git a/src/Psalm/Internal/Cli/LanguageServer.php b/src/Psalm/Internal/Cli/LanguageServer.php index 50d1318cb..f78e4d7f6 100644 --- a/src/Psalm/Internal/Cli/LanguageServer.php +++ b/src/Psalm/Internal/Cli/LanguageServer.php @@ -62,7 +62,7 @@ final class LanguageServer public static function run(array $argv): void { gc_disable(); - ErrorHandler::install(); + ErrorHandler::install($argv); $valid_short_options = [ 'h', 'v', diff --git a/src/Psalm/Internal/Cli/Psalm.php b/src/Psalm/Internal/Cli/Psalm.php index b83446b1d..52653747a 100644 --- a/src/Psalm/Internal/Cli/Psalm.php +++ b/src/Psalm/Internal/Cli/Psalm.php @@ -168,7 +168,7 @@ final class Psalm gc_collect_cycles(); gc_disable(); - ErrorHandler::install(); + ErrorHandler::install($argv); $args = array_slice($argv, 1); @@ -191,7 +191,6 @@ final class Psalm exit(1); } - if (array_key_exists('h', $options)) { echo self::getHelpText(); /* diff --git a/src/Psalm/Internal/Cli/Psalter.php b/src/Psalm/Internal/Cli/Psalter.php index 11978e72c..d5f189864 100644 --- a/src/Psalm/Internal/Cli/Psalter.php +++ b/src/Psalm/Internal/Cli/Psalter.php @@ -97,7 +97,7 @@ final class Psalter gc_collect_cycles(); gc_disable(); - ErrorHandler::install(); + ErrorHandler::install($argv); self::setMemoryLimit(); diff --git a/src/Psalm/Internal/Cli/Refactor.php b/src/Psalm/Internal/Cli/Refactor.php index 9010b7c53..e6caa6f71 100644 --- a/src/Psalm/Internal/Cli/Refactor.php +++ b/src/Psalm/Internal/Cli/Refactor.php @@ -72,7 +72,7 @@ final class Refactor gc_collect_cycles(); gc_disable(); - ErrorHandler::install(); + ErrorHandler::install($argv); $args = array_slice($argv, 1); diff --git a/src/Psalm/Internal/ErrorHandler.php b/src/Psalm/Internal/ErrorHandler.php index 3d96162d2..46fb2e7cf 100644 --- a/src/Psalm/Internal/ErrorHandler.php +++ b/src/Psalm/Internal/ErrorHandler.php @@ -8,6 +8,7 @@ use Throwable; use function defined; use function error_reporting; use function fwrite; +use function implode; use function ini_set; use function set_error_handler; use function set_exception_handler; @@ -24,8 +25,15 @@ final class ErrorHandler /** @var bool */ private static $exceptions_enabled = true; - public static function install(): void + /** @var string */ + private static $args = ''; + + /** + * @param array $argv + */ + public static function install(array $argv = array()): void { + self::$args = implode(' ', $argv); self::setErrorReporting(); self::installErrorHandler(); self::installExceptionHandler(); @@ -67,7 +75,9 @@ final class ErrorHandler ): bool { if (ErrorHandler::$exceptions_enabled && ($error_code & error_reporting())) { throw new RuntimeException( - 'PHP Error: ' . $error_message . ' in ' . $error_filename . ':' . $error_line, + 'PHP Error: ' . $error_message + . ' in ' . $error_filename . ':' . $error_line + . ' for command with CLI args "' . ErrorHandler::$args . '"', $error_code ); }