Commit Graph
1 Commits
Author SHA1 Message Date
5ea8389cd4 fix: return empty text instead of partial garbage when EPUB HTML parse fails (#1161)
* fix: return empty text instead of partial garbage when EPUB HTML parse fails

`_html_to_title_body` used `except Exception: pass` when the
HTMLParser raised. The parser accumulates state incrementally across
`handle_starttag`/`handle_data`/etc. callbacks — so a mid-parse
failure returns whatever partial/corrupted `title` and `_parts`
were accumulated before the error, with zero indication anything went
wrong. EPUB chapter content would be silently garbled.

Now returns ("", "") and logs the parse failure with traceback.

* fix: keep partial chapter text when EPUB HTML parsing fails mid-chapter

The warning log stays — a silent 'except: pass' hid real failures. But
returning empty text made the caller's 'if not body.strip(): continue'
silently drop the whole chapter from the audiobook, trading a possibly-
truncated chapter for a definitely-missing one. Keep whatever the
extractor collected before the failure and log the event. Regression
test builds a real 3-chapter EPUB, injects a mid-chapter parser failure,
and asserts the chapter survives with its pre-failure text (fail-before
verified against the empty-return version).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: mergetest <nizam4103@gmail.com>
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 18:19:02 +05:30