#[non_exhaustive]pub enum DocError {
Show 14 variants
Io(Error),
Encryption(EncryptionUnsupported),
PasswordRequired,
PasswordRequiresNormalisation,
PasswordRequiredR6,
Header(PdfError),
Xref(XrefError),
BadObject {
id: ObjId,
offset: u64,
source: ParseError,
},
ObjectIdMismatch {
expected: ObjId,
found: ObjId,
offset: u64,
},
ObjectStreamMissing {
container: ObjId,
num: u32,
},
ObjectStream {
container: ObjId,
source: ObjStmError,
},
ObjectStreamIdMismatch {
container: ObjId,
index: u32,
expected: u32,
found: u32,
},
NoCatalog,
Recovery(RecoverError),
}Expand description
Errors from loading a document.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Io(Error)
File I/O failed.
Encryption(EncryptionUnsupported)
The document is encrypted with a configuration pdfcer will not decrypt (§7.6). The inner error names which configuration and why — an unimplemented cipher, an unsourced algorithm, a different security handler, or a document no conforming reader may open at all.
Those are four different facts with four different next actions, which is why this is not one flat “encrypted files are unsupported”.
PasswordRequired
The document is encrypted with a configuration pdfcer can decrypt, but no password opened it.
§7.6.3.1 requires trying the empty user password first and silently, so
reaching this error means the empty password was already tried and
failed: the document genuinely has a non-empty user password. The
caller should prompt and retry with
Document::from_bytes_with_password.
N6: ISO 32000-1 states no error model here at all — no retry limit, no reporting requirement, nothing about distinguishing a wrong password from a malformed one. All of that is pdfcer policy.
PasswordRequiresNormalisation
Nothing authenticated, and the supplied password contains
characters /R 5’s password preprocessing may have changed before
hashing — so “wrong password” is not the only explanation.
The Adobe supplement’s step 1 applies SASLprep (RFC 4013) with the Normalize and BIDI options before the UTF-8 conversion. pdfcer implements the UTF-8 conversion and the 127-byte truncation exactly and does not implement SASLprep; neither RFC is staged in the project’s spec corpus, and a stringprep dependency was not taken for a read-only increment.
For an all-ASCII password SASLprep is the identity, so this error can
never arise from one. pdfcer still attempts a non-ASCII password —
SASLprep is the identity for much more than ASCII, and getting it wrong
cannot open a document with a wrong key, only fail to open one with the
right password. This variant exists so that failure does not
masquerade as Self::PasswordRequired’s “you typed it wrong”, which
would send the operator to re-check a password that was correct.
Reported only at /R 5. Password encoding below that is PDFDocEncoding
(T8), a different unimplemented question.
PasswordRequiredR6
Authentication failed at handler revision 6 (AES-256 hardened),
where the failure is not unambiguously “wrong password” (Pass 5.4).
/R 6’s key derivation (Algorithm 2.B) contains a genuine spec
ambiguity — A13, the loop-exit test, which is internally
inconsistent between steps (e) and (f) and produces a different digest
(hence a different key, hence a failed authentication) depending on the
reading. pdfcer defaults to the reading pypdf and Acrobat write
(crate::crypto::r6::A13Reading::PerformThenTest); a document written
by an implementation that took the other reading would fail here with a
correct password. This variant names A13 so that failure is not
reported as “you typed it wrong” (R169: a spec ambiguity is disclosed,
never silently resolved). Raised only at /R 6.
Header(PdfError)
The %PDF- header probe failed — not a PDF.
Xref(XrefError)
The cross-reference machinery failed — a damaged/unreadable
xref chain, or the deliberate /Encrypt capability-gap refusal
(XrefErrorKind::EncryptionUnsupported).
BadObject
An indirect object at an xref-declared offset failed to parse.
Fields
source: ParseErrorThe underlying structural error.
ObjectIdMismatch
The object parsed at an offset doesn’t match the xref entry that pointed there (wrong number or generation) — the table and body disagree; strict Pass 1 refuses rather than guessing which is right.
Fields
ObjectStreamMissing
A type-2 cross-reference entry (§7.5.8.3) named an object stream that is not present as a loadable file-level object.
§7.5.7: “there shall be an entry for it in a cross-reference table or cross-reference stream” — so a missing container means the file’s own xref contradicts itself.
Fields
ObjectStream
An object stream (§7.5.7) could not be decoded or read.
ObjectStreamIdMismatch
The object number stored in an object stream’s pair table
disagrees with the object number its type-2 cross-reference
entry promised — the xref and the container contradict each
other, and the strict loader refuses rather than picking one
(the same posture as DocError::ObjectIdMismatch for
file-level objects).
Fields
NoCatalog
The trailer has no usable /Root (Table 15 requires it; a
conformant update trailer always repeats it — see the RAG’s
gotcha on why fallback-to-older-trailers is a repair heuristic,
not Pass 1 behavior).
Recovery(RecoverError)
Cross-reference recovery (decision 013) was attempted after the
strict load failed, but could not produce a document — no
confirmable objects, no /Catalog, or the entry cap. A named
fail-clean refusal, never a partial/garbage document. (An encrypted
recovered file is refused as XrefErrorKind::EncryptionUnsupported
via DocError::Xref instead, matching the clean-path capability
gap.)
Trait Implementations§
Source§impl Error for DocError
impl Error for DocError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()