Skip to content

Restore the error handler in finally, through one shared helper - #103

Merged
gravitypdf-bot merged 1 commit into
mainfrom
fix/issue-95
Oct 25, 2026
Merged

gravitypdf-bot merged 1 commit into
mainfrom
fix/issue-95

Conversation

@gravitypdf-bot

Copy link
Copy Markdown
Contributor

Fixes #95

There were seven copies of set_error_handler() / catch (Exception) / restore_error_handler() in DOM and DOMQuery. Because they caught only QueryPath\Exception, any other throwable (a TypeError, or an exception from a stream wrapper) left QueryPath's handler installed for the rest of the request. They now all go through DOM::withErrorHandler($exceptionClass, $callback, $types), which restores the handler in finally.

Each call site keeps its exception class and error levels. In particular writeHTML() still uses ParseException; #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 duplicated load() branch.

Tests: testErrorHandlerRestoredAfterForeignThrowable uses a new ThrowingStreamWrapper fixture to throw a RuntimeException inside writeXML(), writeHTML(), writeHTML5() and a load with a stream context. It then checks that the previous handler is back. The first three cases fail on main; writeHTML5() already used finally after #89.

parseXMLString() and prepareInsert() have no such test, because I couldn't find a reliable way to make them throw a non-QueryPath exception.

🤖 Generated with Claude Code

@gravitypdf-bot gravitypdf-bot changed the title Consolidate the seven set_error_handler/restore_error_handler blocks into one finally-based helper Restore the error handler in finally, through one shared helper Oct 25, 2026
@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.55%. Comparing base (b40b4c3) to head (ee074dc).
⚠️ Report is 3 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jakejackson1 jakejackson1 added the enhancement New feature or request label Oct 25, 2026
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
gravitypdf-bot merged commit 389b069 into main Oct 25, 2026
12 checks passed
@gravitypdf-bot
gravitypdf-bot deleted the fix/issue-95 branch October 25, 2026 23:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consolidate the seven set_error_handler/restore_error_handler blocks into one finally-based helper

2 participants