#[non_exhaustive]pub enum LoadAnomaly {
DuplicateDictKey {
object: Option<ObjId>,
key: Vec<u8>,
kept: Object,
discarded: Object,
},
StreamLengthRecovered {
object: ObjId,
},
MissingEndobjRecovered {
object: ObjId,
},
ObjectUnreadable {
object: ObjId,
reason: String,
},
}Expand description
One thing the file said that contradicted itself, and what pdfcer decided
about it (Pass 283.0).
§The operator ruling this exists to satisfy
“We should be making pdfcer so that it opens pdfs that have errors, and have a way that it manages those errors such that they aren’t fatal, and if the user can intervene in a decision that should always be an option along with them not having to intervene.”
Three obligations in one sentence, and this type carries all three:
- Not fatal — the document loads.
- Intervention is possible — the record names the object, the key, the
value kept and the value discarded, which is everything a shell needs to
offer the operator the other choice and re-load with it
(
crate::parser::DuplicateKeyPolicy). - Intervention is not required — pdfcer already picked, the default is documented, and a caller that never reads this list gets a working document.
It is a disclosure, not a prompt: project rule 4 as narrowed by decision 059 — the inferred value is live document state, and what pdfcer guessed is reported off to the side rather than gating the open.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
DuplicateDictKey
One dictionary named the same key twice (§7.3.7) and pdfcer kept one of the values.
Both values are carried, not just the winner. A count would say that pdfcer chose; a shell offering the operator the choice needs to show what it chose between, and a report that cannot answer “what was the other one?” makes the intervention theoretical.
Fields
object: Option<ObjId>The object whose dictionary contradicted itself. None when the
dictionary is the trailer, which is not an indirect object.
discarded: ObjectThe value pdfcer DISCARDED. A caller offering the choice presents
this as the alternative; a caller re-loading under
crate::parser::DuplicateKeyPolicy::KeepFirst gets it instead.
StreamLengthRecovered
A stream’s /Length was absent, non-integer, unresolvable or simply
wrong, and pdfcer re-derived the data extent by scanning to
endstream (§7.3.8.1).
/Length is REQUIRED by §7.3.8.2 Table 5, so this is a shall
violation — and one every reader recovers from, because the keyword
that ends the data is right there in the file. Refusing costs the whole
document to preserve a number the file itself contradicts.
There is no operator choice to offer here, and that is not an oversight: the alternative to the scanned extent is no object at all. The record exists so the operator learns the file is damaged, not so a decision can be re-taken.
MissingEndobjRecovered
An indirect object’s endobj keyword was missing and pdfcer accepted
the definition anyway, ending it at the next object header (§7.3.10).
Same shape as Self::StreamLengthRecovered: a required keyword the
file omits, an unambiguous end, and no second reading to choose
between.
ObjectUnreadable
One object could not be loaded at all, and the document was loaded without it.
§Why this is continuing rather than guessing
§7.3.10 already defines what a reference to an object that is not there means: “An indirect reference to an undefined object shall not be considered an error by a conforming reader; it shall be treated as a reference to the null object.” An object whose bytes will not parse is an undefined object as far as every consumer is concerned — so omitting it is not a liberty pdfcer takes, it is the behaviour the standard prescribes for the state the file is in.
That is the whole difference between this and a repair: nothing is invented, and the resulting document is one the standard describes.
§What it replaces
DocError::BadObject, ObjectIdMismatch, ObjectStreamMissing,
ObjectStream and ObjectStreamIdMismatch — five ways one bad object
used to cost the whole document. They survive as errors under
LoadOptions::strict.
There is no alternative to offer here either. The choice is between
this object and no document, and reason is carried so the operator
can see WHICH object and WHY rather than being told a count.