#[non_exhaustive]pub enum WriteError {
Show 14 variants
Io(Error),
Xref(XrefOutError),
SpanOutOfRange {
id: ObjId,
span: ByteSpan,
},
RedactionPending,
HybridFullRewrite,
ObjectNumberTooLarge {
num: u32,
max: u32,
},
MissingObject {
num: u32,
},
UnknownDirtyObject {
id: ObjId,
},
RecoveredBaseForbidsIncremental,
EncryptedSaveUnsupported,
Rc4AppendRefused,
EntropyUnavailable,
RewriteReload(Box<DocError>),
NothingToLinearize,
}Expand description
Why a save could not be completed.
Every variant is a named, counted refusal rather than a best-effort degradation — the R27 fail-clean posture applied to the write side. A writer that guesses produces a plausible, working, wrong file, which is the worst possible failure shape for this subsystem (decision 007 W4).
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Io(Error)
File I/O failed.
Xref(XrefOutError)
A cross-reference section could not be emitted.
SpanOutOfRange
An object’s retained ByteSpan does not lie inside the
document’s buffer — a provenance bug, and one that must never be
papered over by emitting a truncated object.
Fields
RedactionPending
A save was requested on a session that has a deferred redaction
pending (pdfcer_core::edit::EditSession::apply_redactions_deferred,
Pass 250.2).
A deferred redaction leaves the un-redacted content in the live
session so the operator’s undo history is preserved; the removal is
carried out only by
pdfcer_core::edit::EditSession::save_applying_redaction, which runs the
surgery over the current state and emits clean bytes. Both ordinary
save modes are refused meanwhile: an incremental save would append
a delta over the un-redacted base and leak the content via /Prev
(ARCHITECTURE.md §5.2), and a full rewrite would emit the marks
with the content still present (an unapplied redaction — a footgun, not
a leak). Refusing by name, and pointing at the verb that is safe, is the
honest outcome.
HybridFullRewrite
A full rewrite was requested for a hybrid-reference file
(§7.5.8.4) whose /XRefStm pdfcer could not parse (Pass 281.0).
§NARROWED. This used to fire for EVERY hybrid file.
The original reasoning is kept verbatim, because it is instructive about how a refusal outlives its cause:
“Rebuilding that unit from a merged view requires re-deriving which objects were hidden and re-checking §7.5.8.4’s recursive visibility rule, which is Pass 3.2 work at the earliest. Normalizing the file to a single non-hybrid section instead would destroy its pre-1.5 readability, which R33 forbids outright.”
Both halves were true and the conclusion did not follow. The merged
view was the obstacle, and the merge is pdfcer’s own: the loader now
retains which objects the /XRefStm established
(crate::document::Document::hybrid_partition), which is the single
fact merge_first_wins destroyed. Nothing has to be re-derived — and
re-deriving would have been wrong, because §7.5.8.4’s visibility rule
says what a producer may hide while a rewrite must reproduce what
this file did hide.
Nor is the file normalized: save_full emits the same three-part unit —
main table with the hidden objects free at generation 65535, the stream,
and an update section naming it — so the pre-1.5 view survives and R33
is honoured rather than waived.
§What it cost while it stood
R35 forces a redaction to a full rewrite — an incremental save leaves
the un-redacted bytes in a prior revision — so this refusal made
redaction unreachable on every hybrid file, and the remedy it named
(“use incremental save”) was the one thing a redaction may not take.
Reported by pdfcer-gui on the operator’s own SolidWorks drawing, which
he had asked about three times.
§What still refuses
A file whose trailer names an /XRefStm that does not parse. The file
says it hides objects; pdfcer cannot say which; either partition would
be a guess, and a wrong guess yields a file that opens with an outline
or a structure tree silently missing. A broken /XRefStm is
deliberately non-fatal to loading (§7.5.8.4 guarantees the visible
graph resolves without it) and is fatal to a rewrite.
ObjectNumberTooLarge
A full rewrite was asked to build a cross-reference table up to an
object number beyond [save::MAX_REWRITE_OBJECT_NUMBER].
§7.5.4 requires a single-section full rewrite to carry one entry
per object number from 0 to the highest defined in the file, so
the writer’s cost is set by the largest object NUMBER rather than
by how many objects the file contains. A small file naming one
enormous number therefore asks for an enormous table: pdfium’s
bug_455199.pdf is 1.2 KB, names 2147483648 0 obj, and would
require 2,147,483,649 entries — measured at ~27 MB/s of steady
allocation with the CPU pinned, i.e. about an hour of apparent
progress before the allocator gives up.
Refusing by name is the honest outcome, and the alternatives are both worse: grinding is an unrecoverable freeze in the GUI, and emitting a sparse table instead would break §7.5.4’s completeness requirement — trading a hang for a malformed file.
Reading such a file is unaffected; this bounds the writer
only. inspect and extract-text both succeed on the file above.
Fields
MissingObject
The document’s cross-reference table names an object the loader did not parse — the table and the object map disagree.
UnknownDirtyObject
An object named in the dirty set is not present in the document.
RecoveredBaseForbidsIncremental
save_incremental was requested for a document loaded via
cross-reference recovery (decision 013).
A recovered document had a broken base cross-reference table, so
an incremental append is not merely undesirable but structurally
impossible: the appended section’s /Prev would have to point at a
cross-reference section that does not correctly exist, and the
preserved base bytes are not a valid revision to build on. Its save
is therefore a mandatory full rewrite (save_full, which
emits a fresh valid classic cross-reference); incremental is refused
by name here.
This is the recovered-base-forces-full-rewrite standing rule R67 (decision 013 §9; librarian-assigned — “R59” was proposed but R59/R60/R61 were already taken, so R67 is the assigned number). It is a sibling of R35 (redaction forces full rewrite) and R58 (removal/scrub forces full rewrite): §5.6’s “never normalize” does not bind a recovered file, because its base was already invalid.
EncryptedSaveUnsupported
A full rewrite was asked of a document loaded from an encrypted file (§7.6).
Load decrypts stream data in the retained buffer and strings in the
parsed objects, so a full rewrite’s verbatim copies would emit a file
whose /Encrypt claims encryption its content no longer has — one no
reader can open. Save incrementally (which appends under the existing
handler), or re-encrypt / remove encryption, which re-serialise every
object.
Rc4AppendRefused
An incremental save of an RC4-encrypted document under the
default Rc4Append::Refuse. The routes: opt in with
Document::set_rc4_append
(the CLI’s --allow-rc4-append), re-encrypt with AES-256, or remove
the encryption. Decision 190.
The operating system’s random-number source was unreachable, so no fresh AES initialisation vector (§7.6.2) could be made. Nothing was written.
RewriteReload(Box<DocError>)
pdfcer could not reload a full rewrite it had just produced, so a step that needs the rewrite as a document (an optimize rebuild) stopped. A writer bug; nothing was written.
NothingToLinearize
Linearizing (Annex F) needs a catalog with at least one page, and the document has neither. Nothing was written.
Trait Implementations§
Source§impl Debug for WriteError
impl Debug for WriteError
Source§impl Display for WriteError
impl Display for WriteError
Source§impl Error for WriteError
impl Error for WriteError
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()