-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patherror.rs
More file actions
140 lines (134 loc) · 5.48 KB
/
Copy patherror.rs
File metadata and controls
140 lines (134 loc) · 5.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
use core::fmt;
/// Everything tlottie can fail with. The library never panics: any input,
/// however malformed or hostile, must surface as one of these.
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum Error {
/// The input is not valid JSON. `offset` is a byte offset into the input.
Json {
/// Byte offset into the input where the error was detected.
offset: usize,
/// What exactly was wrong.
kind: JsonErrorKind,
},
/// Valid JSON, but not a Lottie composition we can make sense of
/// (e.g. missing width/height/frame rate, malformed keyframe structure).
InvalidLottie {
/// Byte offset into the input where the error was detected.
offset: usize,
/// Human-readable description of the problem.
what: &'static str,
},
/// A hard resource limit was exceeded (see [`crate::Limits`]).
LimitExceeded(Limit),
/// The composition has no renderable content at all.
Empty,
}
/// What exactly was wrong with the JSON.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum JsonErrorKind {
/// Input ended in the middle of a value.
UnexpectedEof,
/// A byte that doesn't belong at this position.
UnexpectedByte(u8),
/// Malformed or non-finite number.
BadNumber,
/// Malformed string.
BadString,
/// Malformed escape sequence inside a string.
BadEscape,
/// Extra non-whitespace content after the top-level value.
TrailingData,
}
/// Which resource limit tripped.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum Limit {
/// Input larger than [`crate::Limits::max_input_bytes`].
InputBytes,
/// JSON nesting deeper than [`crate::Limits::max_nesting_depth`].
NestingDepth,
/// More layers than [`crate::Limits::max_layers`].
Layers,
/// More shapes in one layer than [`crate::Limits::max_shapes_per_layer`].
ShapesPerLayer,
/// More paints in one layer than [`crate::Limits::max_paints_per_layer`].
PaintsPerLayer,
/// Paints in one layer reference too many cumulative geometry-source items.
PaintSourceItemsPerLayer,
/// More focal radial gradient paints than [`crate::Limits::max_focal_radial_gradients_per_layer`].
FocalRadialGradientsPerLayer,
/// Focal radial gradient paints expand beyond [`crate::Limits::max_focal_radial_gradient_expansion`].
FocalRadialGradientExpansion,
/// More painted shape layers than [`crate::Limits::max_painted_shape_layers`].
PaintedShapeLayers,
/// More solid layers than [`crate::Limits::max_solid_layers`].
SolidLayers,
/// More keyframes on one property than [`crate::Limits::max_keyframes`].
Keyframes,
/// More points in one path than [`crate::Limits::max_path_points`].
PathPoints,
/// A path coordinate exceeded [`crate::Limits::max_path_coordinate_abs`].
PathCoordinate,
/// More masks in one layer than [`crate::Limits::max_masks_per_layer`].
MasksPerLayer,
/// More retained masks than [`crate::Limits::max_masks`].
Masks,
/// A mask path exceeded [`crate::Limits::max_mask_path_points`].
MaskPathPoints,
/// More dash entries in one stroke than [`crate::Limits::max_dash_elements`].
DashElements,
/// More dashed strokes in one group than [`crate::Limits::max_dashed_strokes_per_group`].
DashedStrokesPerGroup,
/// More gradient strokes in one group than [`crate::Limits::max_gradient_strokes_per_group`].
GradientStrokesPerGroup,
/// A round-join dashed stroke source segment exceeded [`crate::Limits::max_dashed_path_segment_span`].
DashedPathSegment,
/// More gradient stop floats than [`crate::Limits::max_gradient_stop_values`].
GradientStopValues,
/// More Fitzpatrick metadata entries than [`crate::Limits::max_fitz_entries`].
FitzEntries,
/// Precomp references expand beyond [`crate::Limits::max_precomp_expansion`].
PrecompExpansion,
/// Parent chain deeper than [`crate::Limits::max_parent_chain_depth`].
ParentChainDepth,
/// Parent chains total more than [`crate::Limits::max_parent_chain_total_depth`].
ParentChainTotalDepth,
/// A polystar exceeded [`crate::Limits::max_polystar_points`].
PolystarPoints,
/// A repeater exceeded [`crate::Limits::max_repeater_copies`].
RepeaterCopies,
/// More round-corners modifiers than [`crate::Limits::max_round_corners_per_layer`].
RoundCornersPerLayer,
/// More trim modifiers than [`crate::Limits::max_trims_per_layer`].
TrimsPerLayer,
/// Estimated dash pieces exceed [`crate::Limits::max_dashed_piece_estimate_per_group`].
DashedPiecesPerGroup,
/// Compounded repeaters exceed [`crate::Limits::max_repeater_product_per_group`].
RepeaterProductPerGroup,
/// More assets than [`crate::Limits::max_assets`].
Assets,
/// Composition dimensions beyond [`crate::Limits::max_dimension`].
CompositionSize,
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Json { offset, kind } => {
write!(f, "invalid JSON at byte {offset}: {kind:?}")
}
Error::InvalidLottie { offset, what } => {
write!(f, "invalid Lottie at byte {offset}: {what}")
}
Error::LimitExceeded(limit) => write!(f, "resource limit exceeded: {limit:?}"),
Error::Empty => write!(f, "composition has no renderable content"),
}
}
}
// core has no Error trait, so this is the one API difference between the two
// configurations. Display, Debug and the enum itself are unchanged.
#[cfg(feature = "std")]
impl std::error::Error for Error {}
/// Convenience alias: `tlottie::Result<T>` = `Result<T, tlottie::Error>`.
pub type Result<T> = core::result::Result<T, Error>;