Repository navigation
repair: say when a file had to be rebuilt to be read - #43
Merged
Merged
Conversation
Doc.Repaired reports whether any file this document's pages came from had to be rebuilt before it could be read, and `pdfops repair` writes the result out. -check answers the question without writing anything. ⛔ The rebuilding is not new and is not this verb's doing: go-pdfkit/reader repairs a damaged file on its own, quietly, which is the right behaviour for a reader — a caller asking for page three wants page three, not a lecture. What was missing was a way to SAY it happened and to keep the result. This closes BentoPDF's repair-pdf, which is a named entry point over exactly that. It reports on ANY source, not all. A merged document's pages come from several files, and one damaged source is the answer to "did this need repairing"; a true that depended on every source being broken would be false for every real merge. The test asserts both orders, because "any" is not "the first". ⛔ A POSITIVE control comes first: without it, "Repaired() is false" would pass on a fixture that was never broken and the whole test would measure nothing. The fixture helper fails loudly if the file it is handed has no startxref to break, which is the same guard from the other side. The scope is reader's and the README says so rather than implying QPDF's: what is recovered is a cross-reference table that is wrong, missing or points into the middle of something else — the commonest damage, and the kind where the objects are all still there. A file that did not need repairing is said out loud and is NOT an error, so that "repair everything in this directory" can be scripted. Both branches of the verb have their own save, so both have their own unwritable-output test: a healthy file and a damaged one take different paths and the first draft covered only one. 100% statement coverage on both packages with no uncovered statements, go vet and gofmt clean. Co-Authored-By: Claude Opus 5 <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.
Doc.Repaired()reports whether any file this document's pages came from had to be rebuilt before it could be read, andpdfops repairwrites the result out.-checkanswers the question without writing anything.This closes BentoPDF's
repair-pdf.⛔ The rebuilding is not new, and is not this verb's doing
go-pdfkit/readerrepairs a damaged file on its own and quietly, which is the right behaviour for a reader — a caller asking for page three wants page three, not a lecture. What was missing was a way to say it happened and to keep the result. That is the whole of this verb.It reports on any source, not all: a merged document's pages come from several files, and one damaged source is the answer to "did this need repairing". A true that depended on every source being broken would be false for every real merge — and the test asserts both orders, because "any" is not "the first".
⛔ A positive control comes first
Without it,
Repaired() == falsewould pass on a fixture that was never broken and the whole test would be measuring nothing. The fixture helper also fails loudly if the file it is handed has nostartxrefto break — the same guard from the other side.And what comes out is asserted clean:
repair -checkon the result says there was nothing to do. A repair whose output still needs repairing is not one.The scope is reader's, and the README says so rather than implying QPDF's
What is recovered is a cross-reference table that is wrong, missing, or points into the middle of something else — the commonest damage, and the kind where the objects are all still there. It is not a general salvage engine, and a file whose objects are themselves truncated may still be unreadable.
A file that did not need repairing is said out loud and is not an error, so that "repair everything in this directory" can be scripted.
Checks
100 % statement coverage on both packages with zero uncovered statements,
go vetandgofmtclean. Both branches of the verb have their ownsave, so both have their own unwritable-output test — a healthy file and a damaged one take different paths, and the first draft covered only one.🤖 Generated with Claude Code