Repository navigation
Conversation
Only exit codes above 255 were limited. A negative return value or error code was passed to exit() as is and wrapped around, -256 even to 0, reporting success. Map every value outside 0-255 to 255. ApplicationErrorEvent::getExitCode() used ?: and so ignored setExitCode(0), while CommandErrorEvent checks for null. Use the null check in both. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Approved |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
Two inconsistencies in the exit code handling:
execute()only limited exit codes above 255. A negative command return value orThrowablecode was passed toexit()unchanged, where the operating system wraps it modulo 256:-1became 255, and-256became 0, i.e. success. Every value outside 0–255 now becomes 255 (which is also what-1produced before).ApplicationErrorEvent::getExitCode()used?:, sosetExitCode(0)was ignored and the event reported theThrowable's code (or 1) instead.CommandErrorEventalready checked fornull; both now do.execute()still turns anAPPLICATION_ERRORexit code of 0 into 1, so the process exit code for an unhandled error does not change — only listeners that read the event's exit code see the 0 they set.Not changed:
setExitCode()in both error events still writes the exit code into theThrowable'scodeproperty via reflection. Symfony'sConsoleErrorEvent::setExitCode()does the same, and it is how an exit code set by aCOMMAND_ERRORlistener reaches theAPPLICATION_ERRORevent and the process exit code (the newtestCommandErrorExitCodeIsSetByEventListenerpins this). Dropping it would need another way to carry the code from one event to the other.Testing Instructions
ApplicationTest::testExitCodeIsLimitedToTheValidRange(return values 0, 255, 256, -1, -256) andtestErrorExitCodeIsLimitedToTheValidRange(exception code -256): the negative cases fail on4.x-dev(close()receives -1/-256).tests/Event/ApplicationErrorEventTest.phpchecks default, explicit and zero exit codes for both error events;setExitCode(0)fails forApplicationErrorEventon4.x-dev.ApplicationTest::testCommandErrorExitCodeIsSetByEventListenercovers theCOMMAND_ERRORpath (passes before and after).Documentation Changes Required
docs/overview.md: new "Exit codes" section in "Application Events" describing the range, theAPPLICATION_ERRORdefault and theCOMMAND_ERRORhandling.🤖 Generated with Claude Code