[6.0] Reduce the stacktrace length by 1 line per middleware #29251
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.
Hello team
What I suggest here is a minor quality of life improvement during development: it reduces the number of lines in the stacktrace for each middleware from 3 to 2.
On a basic installation of a Laravel app, the stacktrace (as show in the error log) of an exception thrown from a controller action goes from 51 lines to 40.
Currently when an exception is thrown, each middleware that have run takes 3 lines in the stacktrace.
One is for the middleware itself, one for the closure of the base Pipeline class, one for the closure of the Routing Pipeline.
The purpose of the routing Pipeline is to wrap the closure of the base pipeline class in a try/catch block and to send the exception to a method to do proper exception reporting/rendering and to send the response up the middleware stack that already ran.
My change moves the try/catch blocks to the base pipeline class allowing the the Routing Pipeline, to not overwrite the
prepareDestination()
andcarry()
methods.The exception isn't handled in the base pipeline (it just throws it again) but is handled as usual by the routing pipeline.
The effect is one less closure, and one less line in the stacktrace, per middleware, while exceptions are still properly handled and the generated response is passed up the middleware stack.
Thanks for your work !