Skip to content

0.4.0: when a check cannot load, say a package is missing - #5

Merged
Waiga merged 1 commit into
mainfrom
fix/dependency-error-inside-a-check
Sep 20, 2026
Merged

Waiga merged 1 commit into
mainfrom
fix/dependency-error-inside-a-check

Conversation

@Waiga

@Waiga Waiga commented Sep 20, 2026

Copy link
Copy Markdown
Owner

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:

run.py catches a per-check exception and records "the check did not complete
(DependencyError)" under NOT CHECKED. If a DependencyError ever arises inside a
check rather than at load, it will be reported as a check failure rather than as a
missing dependency. That is still honest, so I left it rather than widen the blast
radius of this PR.

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.

Site Before Now
run.py page check loop the check did not complete (DependencyError) names the package
run.py document check loop same handler, same sentence names the package
content.py read_page the page's drawing instructions could not be read (DependencyError), filed as a blind spot names the package, still a blind spot
run.py _page_box swallowed in silence by a bare except Exception: continue names the package
load(), three sites fixed in 0.3.0 unchanged

_page_box is the one worth pausing on. It said nothing at all, which is worse
than saying it badly. The page lost its area, picture_share then computed as
zero, 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_share is the only other call in the run path and it cannot raise: it is
arithmetic over geometry already collected, with no pypdf call in it.

Pillow does not raise DependencyError

The 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:

pypdf 5.1.0   -> ImportError: pillow is required to do image extraction. It can be
                 installed via 'pip install pypdf[image]'
pypdf 6.19.0  -> ImportError: pillow is required to do image extraction. It can be
                 installed via 'pip install pypdf[image]'

grep -rn "raise DependencyError" over pypdf 6.19.0 returns eight sites and not one
of them is Pillow: six are the cryptography fallback provider, two are the
jbig2dec binary. Pillow is a guarded import, so it arrives as a plain
ImportError.

So the handler catches a failed import as well, ModuleNotFoundError included by
subclassing. 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 ImportError text so the reader sees
exactly 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:

  • 3 is returned ahead of 1. Both already mean do not send, so nothing that
    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.
  • 3 ignores --fail-on, including never. That flag selects which finding
    levels matter. A missing package is not a finding.

For scripts reading JSON rather than exit codes, the same fact is a new
missing_packages list, empty on every ordinary run, so nothing has to match on
prose.

What the reader actually sees

NOT CHECKED
------------------------------------------------------------------------
  - text_too_small_to_read on page 1
      Your file is not the problem. Something this tool needs is not
      installed, and it could not run without it: pillow is required to
      do image extraction. It can be installed via 'pip install
      pypdf[image]'. This page was not examined for it. Install what it
      needs and run this again. For a Python package that usually means
      pip install --upgrade before-you-send.

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 jbig2dec binary, and telling somebody to pip
install 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.

108 passed                  origin/main, before
18 failed, 108 passed       new tests against unmodified source
126 passed                  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 of
missing-package output covering six message shapes at four sites in both formats.

TOTAL punctuation dashes: 0
exception class names reaching the user: 0
tracebacks: 0
exit codes across all 48 missing-package runs: 3

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, and
the regex was wrong: \s matched the newline before them. Recorded because a proof
that has been corrected is worth more than one that was right first time by luck.

Version: minor, not patch

0.3.0 to 0.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 json carries a new field. A pipeline written
against 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/main and
on this branch and diffed.

366a367
>   "missing_packages": [],
863a865
>   "missing_packages": [],

That is the entire difference. Text output is byte for byte identical, every exit
code is identical, and --help is identical. The README carries no JSON sample, so
no block needed regenerating. The README's exit code paragraph did need rewriting,
because it said 3 meant the tool "read nothing", which is no longer true.

The article backlink on main is untouched, so releasing this carries it to the
package description on the index.

Residue, stated rather than left silent

About forty narrower except Exception handlers remain inside individual checks and
inside 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

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>
@Waiga
Waiga merged commit dce15b4 into main Sep 20, 2026
9 checks passed
@Waiga
Waiga deleted the fix/dependency-error-inside-a-check branch September 20, 2026 08:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant