-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] fix status and exit code #8202
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
Conversation
I don't see any connection between exception and console application failure exit codes. First could be anything and second should be integer between 1 and 254. You can't just draw connection between two and hope that all your userland exceptions would have integer code in between 1 and 254. And if you can't - this functionality (exiting with exception code) is simply unreliable and doesn't make any sense whatsoever. If there's no exception - user controls exit code, if there IS uncaught exception - app should exit with |
@everzet this is a bug fix PR. You are proposing to break bc that should be discussed elsewhere. |
@Tobion then I don't see how this bugfix fixes the issue of not getting In my opinion this whole behaviour of exiting with exception code is a bug. It never worked properly, it never will. Simply because initial assumption is wrong - those two codes are not the same thing. |
@everzet you will never get a 404 exit code because of this: if ($statusCode > 254) {
$statusCode = 254;
} |
@stof exactly. And based on the initial behaviour (app exit code = exception code) - I should. Hence I assume either initial behaviour is wrong or this bugfix doesn't really fix anything :) |
@everzet could you please open another issue for whatever you want. So this PR does not get polluted with unrelated things. |
@Tobion I actually think this is the right place to discuss this issue, 'cause if we decide to change the approach your PR would need to be updated. I agree with @everzet, exception codes have nothing to do with console exit codes. Passing them only in some cases (when it happen they with within the 0-244 range), while changing in others (when they're non integers or out of range) isn't intuitive. About your PR: those nested IFs look ugly. I'm pretty sure it could be simplified. I also think it'd be great to add a test case. |
|
Sorry, I thought it was a recent change. If it was always like that, I agree we shouldn't be changing the behaviour now. |
@Tobion if it always was like that, then ok. I completely forgot that we always had those crazy As of
$statusCode = max(1, min(254, intval($e->getCode()))); |
No offense, you guys should research a little more before making suggestions out of nothing. |
- Prevent negative and 0 exit code from being used on exception - Prevent 255+ exit code from being used Fixes symfony#8183, symfony#8202
@Tobion please, stop being defensively offensive in community built around collaboration. |
255 is reserved by PHP and should not be used also put this code inside the codeCoverageIgnore block because it cannot be tested with phpunit
This PR was merged into the 2.1 branch. Discussion ---------- [Console] fix status and exit code Fix #8183 (comment) and http://www.php.net/manual/en/function.exit.php > Exit statuses should be in the range 0 to 254, the exit status 255 is reserved by PHP and shall not be used. The status 0 is used to terminate the program successfully. Commits ------- 6b9180a [Console] ensure exit code between 0-254 445b2e3 [Console] fix status code when Exception::getCode returns something like 0.1
I've merged this PR but reverted the second commit as it changes the current behavior. |
@fabpot ok. I think it would be appropriate to merge the second commit to master then. Because it changes behavior but fixes something that is explicitly mentioned on the php docu. |
Fix #8183 (comment)
and
http://www.php.net/manual/en/function.exit.php