Repository navigation
Restore the error handler in finally, through one shared helper - #103
Merged
Merged
Conversation
finally-based helper
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #103 +/- ##
============================================
+ Coverage 90.38% 90.55% +0.17%
+ Complexity 1430 1425 -5
============================================
Files 25 25
Lines 3181 3166 -15
============================================
- Hits 2875 2867 -8
+ Misses 306 299 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Seven blocks installed initializeFromError() as the error handler and restored it only from catch (QueryPath\Exception), so any other throwable left the handler installed. Route them all through DOM::withErrorHandler(), which restores it in finally. Fixes #95 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gravitypdf-bot
force-pushed
the
fix/issue-95
branch
from
October 25, 2026 23:39
7bc498b to
ee074dc
Compare
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 #95
There were seven copies of
set_error_handler()/catch (Exception)/restore_error_handler()inDOMandDOMQuery. Because they caught onlyQueryPath\Exception, any other throwable (aTypeError, or an exception from a stream wrapper) left QueryPath's handler installed for the rest of the request. They now all go throughDOM::withErrorHandler($exceptionClass, $callback, $types), which restores the handler infinally.Each call site keeps its exception class and error levels. In particular
writeHTML()still usesParseException; #92 changes that, and whichever of the two merges second needs a one-line rebase. While moving the file loader into a closure, I worked out the HTML/XML choice before the call, which removed a duplicatedload()branch.Tests:
testErrorHandlerRestoredAfterForeignThrowableuses a newThrowingStreamWrapperfixture to throw aRuntimeExceptioninsidewriteXML(),writeHTML(),writeHTML5()and a load with a stream context. It then checks that the previous handler is back. The first three cases fail onmain;writeHTML5()already usedfinallyafter #89.parseXMLString()andprepareInsert()have no such test, because I couldn't find a reliable way to make them throw a non-QueryPath exception.🤖 Generated with Claude Code