Repository navigation
0.4.0: when a check cannot load, say a package is missing - #5
Merged
Merged
Conversation
The 0.3.0 pull request closed this defect at three places and said in as many words that it had left a fourth: a DependencyError raised inside a check was caught by the broad handler in run.py and written into the report as "the check did not complete (DependencyError)". Honest, and the same defect that shipped, which is a missing library on our side described to a sender as something about their page. Five sites, not one. The audit the pull request asked for found three more. read_page caught everything and wrote "the page's drawing instructions could not be read (DependencyError)" into a blind spot, which is the same sentence shape in a different section. _page_box swallowed it in silence behind a bare except that continued, which is worse than saying it badly: the page lost its area, the picture share computed as zero, and zero is the number that suppresses the warning about a page that is mostly picture. The document check loop had the same handler as the page check loop. All five are handled before the broad handler now. Pillow does not raise DependencyError. The defect was specified against that class because it carried the cryptography failure, and Pillow was named as the library most likely to go missing next. Measured against both ends of the declared pypdf range, 5.1.0 and 6.19.0, asking a page for its images without Pillow raises a plain ImportError reading "pillow is required to do image extraction". A handler written for DependencyError alone would have caught the case nobody expected and missed the one everybody predicted. The handler catches a failed import too, ModuleNotFoundError included: whatever class it arrives in, a package that is not installed is a fact about the machine and never about the document. Per check, not a whole run failure, and still exit 3. A run where one check could not load is not a run where nothing could be examined, and refusing to print a report the rest of which is sound would be the tool deciding a partial truth is worth less than nothing. So the report is printed in full and the gap is named in it. The code is still 3, because exit 0 is the only code a pipeline reads as send it, and a check that never ran cannot have found anything. 3 is returned ahead of 1 and ignores --fail-on: both codes already mean do not send, the findings are printed either way, and "a check never ran" has nowhere else to go. What the reader sees is what is missing and how to get it, never an exception class. pypdf's own sentence is passed through rather than paraphrased, as 0.3.0 already did for the fatal case. pip is offered as the usual answer rather than promised, because one of the two things pypdf asks for by name is the jbig2dec binary, and sending somebody to pip for a system binary sends them round a loop that cannot close. Minor rather than patch. Nothing a user could observe is fixed, because no path in this tool reaches a missing package today. What changes is the documented contract: exit 3 can now come from a run that produced a report, and --format json carries a missing_packages list. Text output is byte for byte identical on every example and every documented option, so no README sample was regenerated. 18 tests, each one failing before this change. The dash proof was re-run over 230KB of output covering six message shapes at four sites in both formats, plus every example at every documented option, the README and the corpus manifest: zero punctuation dashes, zero exception class names, zero tracebacks. Residue, stated rather than left silent: about forty narrower except Exception handlers inside individual checks and inside the content walker can still swallow a failed import without a word. None is reachable by a missing package on any path this tool exercises, because pypdf raises for cryptography, which load() has already forced by then, and for image decoding, which this tool never calls. Unlike the handler 0.3.0 left, these cannot produce a wrong sentence, only a missing one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
0.3.0 separated "this installation is short a package" from "this file is bad" at
three places: constructing the reader, opening an encrypted file with the empty
password, and walking to the page list. Its pull request then named a survivor and
left it deliberately:
Still honest and still the same defect: a missing library on our side, described to
a sender as something about their page, with a Python class name where the
explanation should be. This closes it.
The audit found five sites, not one
Item 3 of the brief asked whether the same swallow existed anywhere else in the run
path. It did, in three more places, and one of them is worse than the one that was
reported.
run.pypage check loopthe check did not complete (DependencyError)run.pydocument check loopcontent.pyread_pagethe page's drawing instructions could not be read (DependencyError), filed as a blind spotrun.py_page_boxexcept Exception: continueload(), three sites_page_boxis the one worth pausing on. It said nothing at all, which is worsethan saying it badly. The page lost its area,
picture_sharethen computed aszero, and zero is exactly the number that suppresses the warning about a page that
is mostly picture. A missing library would have made the report quieter, which is
the one direction this tool must never fail in.
picture_shareis the only other call in the run path and it cannot raise: it isarithmetic over geometry already collected, with no pypdf call in it.
Pillow does not raise
DependencyErrorThe brief named Pillow as the obvious future trigger, since pypdf needs it for
image work and this tool explicitly does not examine images. That is right about
the trigger and wrong about the class, and the difference would have left this pull
request closing the defect for the case nobody expected while missing the one
everybody predicted.
Measured on 20 September 2026 against both ends of this project's declared pypdf
range:
grep -rn "raise DependencyError"over pypdf 6.19.0 returns eight sites and not oneof them is Pillow: six are the cryptography fallback provider, two are the
jbig2decbinary. Pillow is a guarded import, so it arrives as a plainImportError.So the handler catches a failed import as well,
ModuleNotFoundErrorincluded bysubclassing. Whatever class it arrives in, a package that is not installed is a
fact about this machine and never about the document in front of it.
This does widen what the handler catches. A genuine bad import inside one of our
own checks would now be reported as a missing package rather than as a crashed
check. That reading is correct rather than a regression: a failed import is a
missing package, the message quotes the real
ImportErrortext so the reader seesexactly what is absent, and exit 3 is the right code for a tool that is incomplete.
The decision the brief asked for: per check, and still exit 3
Both, and the brief was right that there is a real argument either way.
Per check, not a whole run failure. A run where one check could not load is not
the event that exit 3 was written for. The document opened, the pages were read,
and every other check ran. Refusing to print that would be the tool deciding a
partial truth is worth less than nothing, which is the opposite of the position it
takes everywhere else. The existing exit 3 message also says "Nothing was examined,
so nothing is reported", and here that sentence would simply be false.
And still exit 3. Exit 0 is the only code a pipeline reads as "send it", and a
check that never ran cannot have found anything. Leaving the run at 0 would be the
whole defect again one level up: an honest NOT CHECKED entry that a person can read
and a script cannot. The report prints in full, on stdout, and the code says there
is a hole in it.
Two precedence calls, both documented in the README and in comments:
gates on non-zero changes. The difference is that the findings are printed either
way, while "a check never ran, and an install will fix it" has nowhere else to go.
--fail-on, includingnever. That flag selects which findinglevels matter. A missing package is not a finding.
For scripts reading JSON rather than exit codes, the same fact is a new
missing_packageslist, empty on every ordinary run, so nothing has to match onprose.
What the reader actually sees
pypdf's own sentence is passed through rather than paraphrased, which is the rule
0.3.0 already set for the fatal case: guessing at which package is missing is the
same class of error as guessing that the file is damaged.
pip is offered as the usual answer rather than promised as the fix. One of the two
things pypdf asks for by name is the
jbig2decbinary, and telling somebody to pipinstall their way to a system binary sends them round a loop that cannot close.
Tests
18 new, every one of them failing before the change and passing after.
They cover each of the five sites, both exception classes,
ModuleNotFoundError, the exit code precedence over findings and over--fail-on never, the JSON field, and two message edge cases:jbig2dec binary is not available.must not produce a double full stop or claim pip fixes a binary,and an exception with an empty message must still read as a sentence.
The control matters as much as the fix, so there are two. A check that crashes for
any other reason must still be reported as a crash, or the separation has only
moved the lie. An ordinary run must still report no missing packages at all.
Dash proof
Re-run so the 0.3.0 guarantee is not silently broken, over every example at every
documented format option,
--help, the README, the corpus manifest, and 230KB ofmissing-package output covering six message shapes at four sites in both formats.
The first attempt at this proof reported 56 hits. All 56 were the report's own
line-start
-list bullets, which are list markers rather than punctuation, andthe regex was wrong:
\smatched the newline before them. Recorded because a proofthat has been corrected is worth more than one that was right first time by luck.
Version: minor, not patch
0.3.0to0.4.0.Nothing a user could observe is fixed, because no path in this tool reaches a
missing package today. Under a strict "did a bug stop happening" reading this is
not even a patch.
What changes is the documented contract, and that is what the number is for. Exit 3
can now be returned by a run that produced a report, which the README previously
defined as impossible, and
--format jsoncarries a new field. A pipeline writtenagainst 0.3.0's exit codes can observe the difference. Minor.
README sample output
Not regenerated, because the printed output did not change. Verified rather than
assumed: both examples were rendered at every documented option on
origin/mainandon this branch and diffed.
That is the entire difference. Text output is byte for byte identical, every exit
code is identical, and
--helpis identical. The README carries no JSON sample, sono block needed regenerating. The README's exit code paragraph did need rewriting,
because it said
3meant the tool "read nothing", which is no longer true.The article backlink on
mainis untouched, so releasing this carries it to thepackage description on the index.
Residue, stated rather than left silent
About forty narrower
except Exceptionhandlers remain inside individual checks andinside the content walker, and each can still swallow a failed import without a
word. None is reachable by a missing package on any path this tool exercises: pypdf
raises for cryptography, which
load()has already forced by the time a check runs,and for image decoding, which this tool never calls. They are also a different and
milder failure than the one being fixed, because they cannot produce a wrong
sentence, only a missing one, and "Anything inside a picture" is already printed as
NOT CHECKED on every run.
Said here rather than fixed, deliberately, and said in full rather than left for the
next audit to find.
🤖 Generated with Claude Code