Repository navigation
Conversation
execute() catches every Throwable and only dispatches the application.error event. Without a dispatcher or a listener for that event the error vanished: a web application answered with "200 OK" and an empty body, and nothing was logged. The new dispatchErrorEvent() still dispatches the event, but logs the throwable through the application logger when no listener is registered. A web application then also sets the status to 500. Applications with an error listener behave as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
execute()catches everyThrowablefromdoExecute()(andcompress()) and only dispatchesapplication.error. When no dispatcher is set or nobody listens to that event, the error disappears: adoExecute()throwingRuntimeException('boom')results inHTTP/1.1 200 OKwith an empty body and no log entry. Route-not-found, database errors and fatalErrors all become blank 200 responses.This PR adds a protected
AbstractApplication::dispatchErrorEvent(\Throwable $throwable): bool, used by bothexecute()implementations. It dispatchesapplication.erroras before; when no listener for it is registered (or no dispatcher is set) it logs the throwable viagetLogger()->error()(with the throwable in theexceptioncontext key) and returnsfalse.AbstractWebApplication::execute()then sets the status to 500 instead of reporting success.Applications that register an error listener are not affected: the event is dispatched as before and the listener stays in charge of logging, status and body.
Behaviour change in 4.x: without an error listener, a failing web request now answers with status 500 instead of 200, and the throwable is passed to the logger. Rethrowing the throwable by default (the other option in the discussion) would be a breaking change and is left for 5.0.
Testing Instructions
New tests:
AbstractApplicationTest::testExecuteLogsErrorWithoutListener/testExecuteDispatchesErrorToListenerAbstractWebApplicationTest::testExecuteWithErrorAndNoListener/testExecuteWithErrorAndListenerThe two "without listener" tests fail without the change in
src/. Manual: letdoExecute()throw in aWebApplicationwithout a dispatcher; before the change the response is200 OK, after it500 Internal Server Errorand the logger receives the error.Documentation Changes Required
Updated:
docs/lifecycle-and-events.md(Error handling),docs/overview.md("No error page"),docs/cli-applications.md,docs/api-reference.md(execute()rows, newdispatchErrorEvent()), and the tutorial pages 07 and 08, which said that an error without a listener produces HTTP 200.🤖 Generated with Claude Code