#[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
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.
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
BadEntry
An entry is present but structurally wrong (not an array, holds a non-number, an odd element count where pairs are required, …).
Fields
BadArrayLength
An array’s length disagrees with the dimensionality every other entry implies. Table 38: the dimensionality “shall be consistent”.
Fields
InvertedInterval
A /Domain or /Range pair had its bounds inverted. Table 38 requires
Domain_2i <= Domain_2i+1.
Fields
TooManyInputs
Input dimensionality exceeded MAX_SAMPLED_INPUTS.
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”).
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.
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.
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.
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
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.”
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.
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.
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”.
StackUnderflow
An operator needed more operands than the stack held (§7.10.5.2, stack underflow).
Fields
PostScriptType
An operand had the wrong type (§7.10.5.2’s “type error (for example,
applying not to a real number)”).
Fields
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
UndefinedResult
The computation had no defined result (§7.10.5.2’s “undefined result (for example, dividing by 0)”).
Fields
StepLimit
Execution passed MAX_PS_STEPS (pdfcer policy — see that constant).
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.”
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.”
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.
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.
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).
Trait Implementations§
Source§impl Clone for FunctionError
impl Clone for FunctionError
Source§impl Debug for FunctionError
impl Debug for FunctionError
Source§impl Display for FunctionError
impl Display for FunctionError
Source§impl Error for FunctionError
impl Error for FunctionError
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()