pdfboss_write/error.rs
1//! Error type for PDF creation. Writing is strict where reading is lenient:
2//! a writer that silently drops or corrupts content is worse than one that
3//! refuses, so every lossy situation is an error, never a skip.
4
5use pdfboss_core::ObjRef;
6
7/// Alias used across the crate.
8pub type Result<T> = std::result::Result<T, Error>;
9
10/// Any error raised while building or serializing a PDF.
11#[derive(Debug, thiserror::Error)]
12pub enum Error {
13 /// Underlying I/O failure while saving.
14 #[error("i/o error: {0}")]
15 Io(#[from] std::io::Error),
16 /// A reserved object was filled twice, or `fill` targeted a
17 /// never-reserved reference.
18 #[error("object {} {} already has a body", .0.num, .0.gen)]
19 AlreadyFilled(ObjRef),
20 /// `finish` found a reserved object that was never filled.
21 #[error("object {} {} was reserved but never filled", .0.num, .0.gen)]
22 Unfilled(ObjRef),
23 /// A `Stream` object appeared nested inside another object; streams are
24 /// only legal as indirect objects (ISO 32000 ยง7.3.8).
25 #[error("stream objects must be indirect, not nested")]
26 NestedStream,
27 /// A character has no code in the target font's encoding.
28 #[error("character {ch:?} is not encodable in {font}")]
29 Unencodable {
30 /// The character that failed to encode.
31 ch: char,
32 /// Base font name of the font that rejected it.
33 font: &'static str,
34 },
35 /// Image bytes could not be understood or are inconsistent.
36 #[error("invalid image: {0}")]
37 Image(String),
38 /// Anything else.
39 #[error("{0}")]
40 Other(String),
41}