Skip to content

Commit 5d83502

Browse files
committed
bug symfony#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 | symfony#20775 | License | MIT | Doc PR | - Commits ------- 67e249d [Debug] Set exit status to 255 on error
2 parents 7890f33 + 67e249d commit 5d83502

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/Symfony/Component/Debug/ErrorHandler.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class ErrorHandler
101101
private static $reservedMemory;
102102
private static $stackedErrors = array();
103103
private static $stackedErrorLevels = array();
104+
private static $exitCode = 0;
104105

105106
/**
106107
* Same init value as thrownErrors.
@@ -477,6 +478,9 @@ public function handleError($type, $message, $file, $line)
477478
*/
478479
public function handleException($exception, array $error = null)
479480
{
481+
if (null === $error) {
482+
self::$exitCode = 255;
483+
}
480484
if (!$exception instanceof \Exception) {
481485
$exception = new FatalThrowableError($exception);
482486
}
@@ -562,7 +566,7 @@ public static function handleFatalError(array $error = null)
562566
return;
563567
}
564568

565-
if (null === $error) {
569+
if ($exit = null === $error) {
566570
$error = error_get_last();
567571
}
568572

@@ -586,15 +590,21 @@ public static function handleFatalError(array $error = null)
586590
} else {
587591
$exception = new FatalErrorException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, true, $trace);
588592
}
589-
} elseif (!isset($exception)) {
590-
return;
591593
}
592594

593595
try {
594-
$handler->handleException($exception, $error);
596+
if (isset($exception)) {
597+
self::$exitCode = 255;
598+
$handler->handleException($exception, $error);
599+
}
595600
} catch (FatalErrorException $e) {
596601
// Ignore this re-throw
597602
}
603+
604+
if ($exit && self::$exitCode) {
605+
$exitCode = self::$exitCode;
606+
register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); });
607+
}
598608
}
599609

600610
/**

0 commit comments

Comments
 (0)