Repository navigation
fix(translate): keep pages with no text instead of failing the run - #137
Merged
Merged
Conversation
BabelDOC raises ExtractTextError ("The document contains no paragraphs.")
on a chunk with no text, and a chunk is one page, so one blank, scanned
or image-only page ended the whole translation as "BabelDOC chunk N
failed". A 346-page book has 37 empty pages, the first of them page 2,
so translating it whole failed four seconds in, every time.
This fix was written on 2026-10-22 (14092cf) but only ever lived on the
unmerged fix/skip-textless-pages and fix/release-freed-memory branches;
no PR was opened, so main never had it. Ported here onto current main.
pdf_pages.pages_without_text screens the selected pages before BabelDOC
runs, sparing them a whole pipeline run; catching ExtractTextError in
run_one_chunk is the backstop for pages with text BabelDOC still can't
use, such as its "too many CID paragraphs" refusal. A skipped page still
emits chunk_ready, re-sending the latest rolling path rather than
rebuilding it, and a run in which every selected page is textless is an
error, not a copy of the source labelled translated.
Re-verified on this branch (PyMuPDF 1.25.5, Argos, the real pipeline):
pages 1-5 of the book failed on main with 0 pages done and now finish
5/5 with pages 2 and 4 unchanged; pages 27-31 finish with the blank 28
and 30 kept and the "Part I" title page translated; page 2 alone is the
"None of the selected pages has text" error; and an ExtractTextError
reported for one of three pages keeps that page and finishes the run.
The screen's 7 tests were seen red against two stubs (one finding no
page, one finding every page) before the real helper.
(cherry picked from commit 14092cf)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
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.
Why
Translating a document that has even one page with no text failed the whole job:
ExtractTextErroron a chunk with no paragraphs, and a chunk is one page. So one blank, scanned or image-only page ends the run.Why it was still happening: this fix was written on 2026-10-22 (
14092cf), but it only ever lived on the unmergedfix/skip-textless-pagesandfix/release-freed-memorybranches. No PR was opened for either, somainand every build since never had it. This PR ports it onto currentmain(processor.pyhad moved under it) and re-verifies it.What changes
pdf_pages.pages_without_textscreens the selected pages before BabelDOC runs. A page with nothing but whitespace is kept as the original and spared a whole pipeline run.run_one_chunk: anExtractTextErrorfrom BabelDOC (BabelDOC passes the exception object itself) marks that chunk skipped instead of failing the run. This covers text BabelDOC still can't use, such as its "too many CID paragraphs" refusal for garbled fonts.chunk_ready. It re-sends the latest rolling path rather than rebuilding it, so "N of M pages" reaches M and the viewer's mask lifts without a reload (maskAfterArtifactwidens the mask for an unchanged path).Test plan
pytest tests: 1432 passed (+7). The screen's tests were seen red against two stubs, one finding no page and one finding every page, before the real helper.ruffclean.Real pipeline, Argos, PyMuPDF 1.25.5 (this branch's pin).
processor.pyhas no unit harness, so these runs are the check:mainBackstop: with BabelDOC reporting
ExtractTextErrorfor one of three pages, that page is kept as the original and the run finishes.Whole 346-page book in
pnpm tauri dev, together with fix(translate): stop the sidecar's RAM climbing with every translated page #136.Conflicts with #136: both PRs touch
processor.py's consumer loop,CLAUDE.mdandtranslation-pipeline.md. Whichever merges second needs a small rebase.🤖 Generated with Claude Code