#[non_exhaustive]pub enum Error {
UnexpectedEof {
at: Position,
},
Syntax {
at: Position,
message: &'static str,
},
LimitExceeded {
limit: Limit,
at: Option<Position>,
},
Type {
expected: &'static str,
context: &'static str,
},
UnsupportedFilter(String),
Decompress(&'static str),
InvalidStructure {
kind: &'static str,
message: &'static str,
},
}Expand description
Everything that can go wrong while lexing, parsing or decoding PDF syntax.
Every fallible public function returns Result; no input is allowed to panic.
Positions are offsets in the buffer that was parsed, reported as
Position::FileOffset: a caller that parsed something other than the file re-tags them
with Error::map_position (laminapdf-cos does, for windows and object streams).
Display formats only fixed text and numbers, never bytes or names read from the input
(ADR 0026 §4).
Added in 0.2.0.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
UnexpectedEof
The input ended before a complete token or object was read.
Syntax
A token or structure did not match what the grammar requires.
Fields
LimitExceeded
A hard Limits value was exceeded (ADR 0003 §3).
Fields
Type
An object had a different type than the structure requires.
Fields
UnsupportedFilter(String)
The stream uses a filter that is not implemented. The name is read from the file, so it is kept here but never formatted (ADR 0026 §4).
Decompress(&'static str)
Compressed data was corrupt.
InvalidStructure
Filter parameters (e.g. a PNG predictor) were malformed.
Implementations§
Source§impl Error
impl Error
Sourcepub const CODES: &'static [&'static str]
pub const CODES: &'static [&'static str]
Every code Error::code can return.
Added in 0.2.0.
Sourcepub const fn code(&self) -> &'static str
pub const fn code(&self) -> &'static str
A stable kebab-case code for this error, part of the public API in Rust, WASM and
TypeScript (listed in fixtures/codes.json).
Added in 0.2.0.
Sourcepub const fn kind(&self) -> ErrorKind
pub const fn kind(&self) -> ErrorKind
The kind of this error (ADR 0026 §2), as fixtures/codes.json lists it for
Error::code (a test checks every variant).
Added in 0.2.0.
Sourcepub fn location(&self) -> Location
pub fn location(&self) -> Location
Where the error was found (ADR 0026 §1.1); empty when there is no position.
Added in 0.2.0.
Sourcepub const fn position(&self) -> Option<Position>
pub const fn position(&self) -> Option<Position>
The tagged position this error carries, if any.
Added in 0.2.0.
Sourcepub fn map_position(self, f: impl FnOnce(Position) -> Position) -> Self
pub fn map_position(self, f: impl FnOnce(Position) -> Position) -> Self
This error with its position passed through f: how a caller re-tags an offset in
the buffer it parsed (Position::shifted for a window of the file,
Position::in_stream for a stream’s decoded data).
Added in 0.2.0.
Trait Implementations§
impl Eq for Error
Source§impl Error for Error
impl Error for Error
1.30.0 · 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()