Skip to main content

FunctionError

Enum FunctionError 

Source
#[non_exhaustive]
pub enum FunctionError {
Show 36 variants NotAFunction, MissingFunctionType, UnknownFunctionType(i64), NotAStream { function_type: i64, }, StreamUnreadable, Filter(FilterError), MissingEntry { key: &'static str, function_type: i64, }, BadEntry { key: &'static str, detail: String, }, BadArrayLength { key: &'static str, expected: usize, got: usize, }, InvertedInterval { key: &'static str, index: usize, low: f64, high: f64, }, TooManyInputs { got: usize, limit: usize, }, BadBitsPerSample(i64), SampleDataTooShort { need: usize, have: usize, }, SampleTableTooLarge, SampleIndexOutOfRange { index: usize, }, DomainIncompatibleWithExponent { n: f64, low: f64, high: f64, }, NotOneInput { function_type: i64, got: usize, }, NoSubFunctions, SubFunctionArity { index: usize, expected: usize, got: usize, }, BadBounds { detail: String, }, NestingTooDeep { limit: usize, }, PostScriptLex(LexError), PostScriptSyntax { detail: String, }, UnknownOperator(String), PostScriptNestingTooDeep { limit: usize, }, StackOverflow { limit: usize, }, StackUnderflow { op: &'static str, needed: usize, had: usize, }, PostScriptType { op: &'static str, detail: &'static str, }, PostScriptRange { op: &'static str, detail: &'static str, }, UndefinedResult { op: &'static str, detail: &'static str, }, StepLimit { limit: usize, }, OutputArity { expected: usize, got: usize, }, NonNumericOutput { index: usize, }, InputArity { expected: usize, got: usize, }, NonFiniteInput { index: usize, value: f64, }, NonFiniteOutput { index: usize, value: f64, },
}
Expand description

Everything that can stop a function from loading or evaluating.

Follows the Rust API Guidelines’ C-GOOD-ERR: implements std::error::Error through thiserror and is Send + Sync + 'static. #[non_exhaustive] so later work (a cubic-spline evaluator, a type 5) can add variants without a breaking change.

Every variant names what was wrong specifically enough that a caller can put it in front of the operator. That is the whole point — see the module docs’ refusal-posture section for why there is no Unknown catch-all and no silent degradation.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

NotAFunction

The object is not a dictionary or a stream, so it cannot be a function (§7.10.1: every type is one or the other).

§

MissingFunctionType

/FunctionType is absent or is not an integer.

§

UnknownFunctionType(i64)

/FunctionType held a value §7.10 does not define. 1 reaches here too — there is no type 1 (module docs).

§

NotAStream

The type requires a stream (types 0 and 4 carry their payload as stream data) but the object was a bare dictionary.

Fields

§function_type: i64

The declared /FunctionType.

§

StreamUnreadable

The stream’s byte span could not be served by the view — a truncated file or a span from a different document (see pdfcer_model::view::StreamSource::slice).

§

Filter(FilterError)

The stream’s /Filter chain failed to decode.

§

MissingEntry

A required entry is absent.

Fields

§key: &'static str

The absent key, without its leading solidus.

§function_type: i64

The declared /FunctionType.

§

BadEntry

An entry is present but structurally wrong (not an array, holds a non-number, an odd element count where pairs are required, …).

Fields

§key: &'static str

The offending key, without its leading solidus.

§detail: String

What specifically was wrong.

§

BadArrayLength

An array’s length disagrees with the dimensionality every other entry implies. Table 38: the dimensionality “shall be consistent”.

Fields

§key: &'static str

The offending key, without its leading solidus.

§expected: usize

The length the rest of the function implies.

§got: usize

The length actually found.

§

InvertedInterval

A /Domain or /Range pair had its bounds inverted. Table 38 requires Domain_2i <= Domain_2i+1.

Fields

§key: &'static str

Domain or Range.

§index: usize

Which pair (0-based).

§low: f64

The declared lower bound.

§high: f64

The declared upper bound.

§

TooManyInputs

Input dimensionality exceeded MAX_SAMPLED_INPUTS.

Fields

§got: usize

The declared m.

§

BadBitsPerSample(i64)

/BitsPerSample was not one of VALID_BITS_PER_SAMPLE.

§

SampleDataTooShort

The sample table implied by /Size, /Range and /BitsPerSample needs more bytes than the decoded stream holds (§7.10.2: “The stream data shall be long enough to contain the entire sample array”).

Fields

§need: usize

Bytes the table requires.

§have: usize

Bytes actually decoded.

§

SampleTableTooLarge

/Size’s product overflowed usize, or the resulting bit count did. The table cannot exist, so the arithmetic is refused rather than wrapped.

§

SampleIndexOutOfRange

A sample index fell outside the validated table. Structurally unreachable — the load-time length check makes every index computable from a clamped input in range — and reported rather than papered over so that a future refactor which breaks the invariant is visible instead of silently reading zeros.

Fields

§index: usize

The offending flat sample index.

§

DomainIncompatibleWithExponent

Type 2’s /N is non-integral while /Domain admits a negative x, or /N is negative while /Domain admits x = 0. §7.10.3: “Values of Domain shall constrain x in such a way that if N is not an integer, all values of x shall be non-negative, and if N is negative, no value of x shall be zero.” Both cases would evaluate to NaN or infinity.

Fields

§n: f64

The exponent.

§low: f64

Domain_0.

§high: f64

Domain_1.

§

NotOneInput

A type 2 or type 3 function declared more than one input. §7.10.3 and §7.10.4 both restrict these to m = 1.

Fields

§function_type: i64

The declared /FunctionType.

§got: usize

The m implied by /Domain.

§

NoSubFunctions

A type 3’s /Functions array was empty. §7.10.4 allows k = 1 but not k = 0 — with no sub-function there is nothing to evaluate and n is undefined.

§

SubFunctionArity

Two sub-functions of a type 3 disagree on output dimensionality. §7.10.4: “The output dimensionality of all functions shall be the same.”

Fields

§index: usize

Which sub-function disagreed.

§expected: usize

The count set by sub-function 0.

§got: usize

The count this one declared.

§

BadBounds

/Bounds was not in non-decreasing order, or a bound fell outside /Domain. §7.10.4: “Bounds elements shall be in order of increasing value, and each value shall be within the domain defined by Domain.”

Fields

§detail: String

What specifically was wrong.

§

NestingTooDeep

Function nesting (type 3 sub-functions) exceeded MAX_FUNCTION_DEPTH, which also catches a reference cycle through /Functions.

§

PostScriptLex(LexError)

The type 4 program stream did not lex.

§

PostScriptSyntax

The type 4 program lexed but did not parse (missing outer braces, a brace block not consumed by if/ifelse, an unterminated block, …). §7.10.5.2 makes reader-side syntax detection a shall.

Fields

§detail: String

What specifically was wrong.

§

UnknownOperator(String)

A token in the type 4 program is not one of Table 42’s 42 operators.

The set is closed: §7.10.5.1 introduces it as “Table 42 lists the operators that can be used in this type of function”, and the same paragraph bans everything a name could otherwise refer to — “no composite data structures such as strings or arrays, no procedures, and no variables or names”. So an unrecognised token is a defect in the file, not a gap in pdfcer.

§

PostScriptNestingTooDeep

{ } nesting exceeded MAX_PS_NESTING.

Fields

§

StackOverflow

The operand stack grew past PS_STACK_LIMIT. §7.10.5.2 lists stack overflow first among the errors a reader “shall detect and report”.

Fields

§

StackUnderflow

An operator needed more operands than the stack held (§7.10.5.2, stack underflow).

Fields

§op: &'static str

The operator that underflowed.

§needed: usize

Operands required.

§had: usize

Operands present.

§

PostScriptType

An operand had the wrong type (§7.10.5.2’s “type error (for example, applying not to a real number)”).

Fields

§op: &'static str

The operator that rejected its operand.

§detail: &'static str

What was expected and what arrived.

§

PostScriptRange

An operand was outside an operator’s mathematical domain (§7.10.5.2’s “range error (for example, applying sqrt to a negative number)”).

Fields

§op: &'static str

The operator that rejected its operand.

§detail: &'static str

What was out of range.

§

UndefinedResult

The computation had no defined result (§7.10.5.2’s “undefined result (for example, dividing by 0)”).

Fields

§op: &'static str

The operator with no defined result.

§detail: &'static str

Why it is undefined.

§

StepLimit

Execution passed MAX_PS_STEPS (pdfcer policy — see that constant).

Fields

§

OutputArity

The program finished with an operand count that does not match /Range. §7.10.5.1: “It shall be an error for the number of remaining operands to differ from the number of output variables specified by Range.”

Fields

§expected: usize

n, from /Range.

§got: usize

What the program actually left.

§

NonNumericOutput

The program left a boolean where /Range requires a number. §7.10.5.1 makes this an error in the same sentence as the count mismatch: “…or for any of them to be objects other than numbers.”

Fields

§index: usize

Which output position held the boolean.

§

InputArity

PdfFunction::eval was handed the wrong number of inputs. Not a file defect — a caller defect — but reported the same way rather than padded or truncated, because a DeviceN transform fed the wrong tint count would otherwise return a confidently wrong colour.

Fields

§expected: usize

m.

§got: usize

What the caller passed.

§

NonFiniteInput

An input was NaN or infinite.

Clamping cannot rescue these: Rust’s f64::max returns the non-NaN operand, so a NaN tint clamped to /Domain would silently become the domain’s lower bound — a fabricated value wearing the shape of a real one. Refused instead.

Fields

§index: usize

Which input.

§value: f64

The offending value.

§

NonFiniteOutput

An output was NaN or infinite after /Range clamping (so it can only happen when /Range is absent, since clamping maps infinities onto finite bounds).

Fields

§index: usize

Which output.

§value: f64

The offending value.

Trait Implementations§

Source§

impl Clone for FunctionError

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FunctionError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for FunctionError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for FunctionError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl From<FilterError> for FunctionError

Source§

fn from(source: FilterError) -> Self

Converts to this type from the input type.
Source§

impl From<LexError> for FunctionError

Source§

fn from(source: LexError) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for FunctionError

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FunctionError

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.