Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include CLI args in PHP errors to more quickly identify run issues in CI #8724

Merged
merged 1 commit into from Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
14 changes: 12 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,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();
Expand Down Expand Up @@ -67,7 +75,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