Skip to content

Commit

Permalink
include CLI args in PHP errors to more quickly identify run issues in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmuffme committed Nov 20, 2022
1 parent 6d03c32 commit 0bebf6c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Cli/LanguageServer.php
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions src/Psalm/Internal/Cli/Psalm.php
Expand Up @@ -168,7 +168,7 @@ public static function run(array $argv): void
gc_collect_cycles();
gc_disable();

ErrorHandler::install();
ErrorHandler::install($argv);

$args = array_slice($argv, 1);

Expand All @@ -191,7 +191,6 @@ public static function run(array $argv): void
exit(1);
}


if (array_key_exists('h', $options)) {
echo self::getHelpText();
/*
Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Cli/Psalter.php
Expand Up @@ -97,7 +97,7 @@ public static function run(array $argv): void
gc_collect_cycles();
gc_disable();

ErrorHandler::install();
ErrorHandler::install($argv);

self::setMemoryLimit();

Expand Down
2 changes: 1 addition & 1 deletion src/Psalm/Internal/Cli/Refactor.php
Expand Up @@ -72,7 +72,7 @@ public static function run(array $argv): void
gc_collect_cycles();
gc_disable();

ErrorHandler::install();
ErrorHandler::install($argv);

$args = array_slice($argv, 1);

Expand Down
10 changes: 8 additions & 2 deletions src/Psalm/Internal/ErrorHandler.php
Expand Up @@ -8,6 +8,7 @@
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;
Expand All @@ -24,8 +25,11 @@ final class ErrorHandler
/** @var bool */
private static $exceptions_enabled = true;

public static function install(): void
private static $args = '';

public static function install(array $argv = array()): void
{
self::$args = implode(' ', $argv);
self::setErrorReporting();
self::installErrorHandler();
self::installExceptionHandler();
Expand Down Expand Up @@ -67,7 +71,9 @@ private static function installErrorHandler(): void
): 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
);
}
Expand Down

0 comments on commit 0bebf6c

Please sign in to comment.