Repository navigation
Preserve the current Arbre element when within(nil) raises - #757
Open
javierjulio wants to merge 1 commit into
Open
javierjulio wants to merge 1 commit into
javierjulio wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #757 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 17 17
Lines 459 459
=========================================
Hits 459 459 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
mgrunberg
approved these changes
Dec 1, 2026
javierjulio
force-pushed
the
fix-context-element-buffer
branch
2 times, most recently
from
December 3, 2026 01:04
80c26ab to
5336ca0
Compare
Context#with_current_arbre_element (aliased as #within) validates its argument and raises ArgumentError when given nil. The raise sat inside the method body, which is covered by the method-level `ensure`, so the `ensure` still ran and popped the element buffer even though nothing had been pushed. That pop removed an element the caller still owned. At the top level it removed the context itself, leaving current_arbre_element as nil, so any further building after rescuing the error failed with a confusing NoMethodError on nil instead of adding to the context. Inside a nested block it silently dropped the enclosing element, so later tags were attached to the wrong parent. Validate the argument before pushing, and wrap only the yield in begin/ensure so the buffer is popped only when something was pushed. This is safe and non-breaking: - With a non-nil element the behavior is unchanged: the element is pushed, the block runs, and the element is popped even if the block raises. - With nil the same ArgumentError is raised with the same message. The only difference is that the buffer is no longer corrupted, which no caller could have relied on, since it left the context unusable. - The public method signature, the #within alias and the return value (the block's result) are unchanged. Add a spec that fails without this change: after rescuing the error the current element is still the context, and new tags are added to it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
javierjulio
force-pushed
the
fix-context-element-buffer
branch
from
December 3, 2026 01:09
5336ca0 to
61e344c
Compare
This branch has not been deployed
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.
within(nil)raisedArgumentErrorbefore it pushed an element, but cleanup still popped the active element. If the caller rescued the error, later tags could attach to the wrong parent or fail to build.The regression spec confirms that
within(nil)raises and that a new tag still attaches to the original parent. It fails onmasterand passes with the fix. All 181 specs passed on Rails 8.0 and 8.1.Low risk and easy to revert. The fix changes only buffer cleanup after argument validation fails.