1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-27 12:55:26 +01:00

Merge pull request #8724 from kkmuffme/include-cli-args-in-php-errors

This commit is contained in:
Bruce Weirdan 2022-11-20 06:28:22 -04:00 committed by GitHub
commit 7869cb548a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 16 additions and 7 deletions

View File

@ -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',

View File

@ -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();
/*

View File

@ -97,7 +97,7 @@ final class Psalter
gc_collect_cycles();
gc_disable();
ErrorHandler::install();
ErrorHandler::install($argv);
self::setMemoryLimit();

View File

@ -72,7 +72,7 @@ final class Refactor
gc_collect_cycles();
gc_disable();
ErrorHandler::install();
ErrorHandler::install($argv);
$args = array_slice($argv, 1);

View File

@ -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<int,string> $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
);
}