bug #22424 [Debug] Set exit status to 255 on error (nicolas-grekas)
This PR was merged into the 2.7 branch.
Discussion
----------
[Debug] Set exit status to 255 on error
| Q | A
| ------------- | ---
| Branch? | 2.7
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes (no easily testable in fact)
| Fixed tickets | #20775
| License | MIT
| Doc PR | -
Commits
-------
67e249dc81
[Debug] Set exit status to 255 on error
This commit is contained in:
commit
5d83502ab5
|
@ -101,6 +101,7 @@ class ErrorHandler
|
|||
private static $reservedMemory;
|
||||
private static $stackedErrors = array();
|
||||
private static $stackedErrorLevels = array();
|
||||
private static $exitCode = 0;
|
||||
|
||||
/**
|
||||
* Same init value as thrownErrors.
|
||||
|
@ -477,6 +478,9 @@ class ErrorHandler
|
|||
*/
|
||||
public function handleException($exception, array $error = null)
|
||||
{
|
||||
if (null === $error) {
|
||||
self::$exitCode = 255;
|
||||
}
|
||||
if (!$exception instanceof \Exception) {
|
||||
$exception = new FatalThrowableError($exception);
|
||||
}
|
||||
|
@ -562,7 +566,7 @@ class ErrorHandler
|
|||
return;
|
||||
}
|
||||
|
||||
if (null === $error) {
|
||||
if ($exit = null === $error) {
|
||||
$error = error_get_last();
|
||||
}
|
||||
|
||||
|
@ -586,15 +590,21 @@ class ErrorHandler
|
|||
} else {
|
||||
$exception = new FatalErrorException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, true, $trace);
|
||||
}
|
||||
} elseif (!isset($exception)) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$handler->handleException($exception, $error);
|
||||
if (isset($exception)) {
|
||||
self::$exitCode = 255;
|
||||
$handler->handleException($exception, $error);
|
||||
}
|
||||
} catch (FatalErrorException $e) {
|
||||
// Ignore this re-throw
|
||||
}
|
||||
|
||||
if ($exit && self::$exitCode) {
|
||||
$exitCode = self::$exitCode;
|
||||
register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); });
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in New Issue