Fix misleading error messages with {capture}#1191
Open
ichaykin wants to merge 3 commits into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes misleading error reporting when rendering fails inside a {capture} block by preventing exceptions thrown during end-of-render cleanup (endRenderCallbacks) from masking the original render-time exception in Template::render().
Changes:
- Track a render-time exception and ensure endRenderCallbacks run in
finally. - Preserve prior behavior where endRenderCallback exceptions are still thrown when rendering succeeds.
- When both render and cleanup fail, prefer the original render exception.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…andling in endRenderCallbacks
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.
Fixes #1032
What does this fix?
This fixes misleading error reporting when an exception is thrown while rendering content inside a
{capture}block.Before this change, the original render exception could be hidden by a later
CaptureRuntime::endRender()exception:That made debugging harder, because the developer had to remove or inspect the {capture} block to find the real error.
What changed?
Template::render() now keeps track of an exception thrown during the actual render phase.
The endRenderCallbacks are still executed in finally, preserving the cleanup behavior. However, if rendering has already failed and an endRenderCallback also throws, the callback exception no longer replaces the original render exception.
If rendering succeeds, callback exceptions keep the previous behavior and are still thrown normally.
Behavior after this change
• If rendering fails inside {capture}, the original render exception is reported.
• If rendering succeeds but an endRenderCallback fails, that callback exception is still reported.
• If both rendering and an endRenderCallback fail, the original render exception wins.