Skip to main content

token_value_map/
error.rs

1//! Error types for token-value-map operations.
2
3use crate::Time;
4
5#[cfg(feature = "builtin-types")]
6use crate::DataType;
7
8/// Error type for token-value-map operations.
9#[derive(Debug, Clone, thiserror::Error)]
10pub enum Error {
11    /// Type conversion method called on incompatible type.
12    #[cfg(feature = "builtin-types")]
13    #[error("{method}: called on incompatible type `{got:?}`")]
14    IncompatibleType {
15        /// The method that was called.
16        method: &'static str,
17        /// The actual data type encountered.
18        got: DataType,
19    },
20
21    /// Conversion between data types is not supported.
22    #[cfg(feature = "builtin-types")]
23    #[error("cannot convert `{from:?}` to `{to:?}`")]
24    ConversionUnsupported {
25        /// The source data type.
26        from: DataType,
27        /// The target data type.
28        to: DataType,
29    },
30
31    /// Failed to parse string as target type.
32    #[error("cannot parse '{input}' as {target_type}")]
33    ParseFailed {
34        /// The input string that failed to parse.
35        input: String,
36        /// The target type name.
37        target_type: &'static str,
38    },
39
40    /// Integer conversion overflow.
41    #[error("integer conversion error: {0}")]
42    IntegerOverflow(#[from] std::num::TryFromIntError),
43
44    /// Cannot create animated value with no samples.
45    #[error("cannot create animated value with no samples")]
46    EmptySamples,
47
48    /// Cannot remove the last sample from animated data.
49    #[error("cannot remove the last sample from animated data")]
50    LastSample,
51
52    /// Type mismatch in animated samples.
53    #[cfg(feature = "builtin-types")]
54    #[error("animated sample type mismatch: expected `{expected:?}`, got `{got:?}` at time {time}")]
55    AnimatedTypeMismatch {
56        /// The expected data type.
57        expected: DataType,
58        /// The actual data type encountered.
59        got: DataType,
60        /// The time at which the mismatch occurred.
61        time: Time,
62    },
63
64    /// Vector length exceeds expected.
65    #[error("vector length {actual} exceeds expected {expected} at time {time}")]
66    VectorLengthExceeded {
67        /// The actual vector length.
68        actual: usize,
69        /// The expected maximum length.
70        expected: usize,
71        /// The time at which the error occurred.
72        time: Time,
73    },
74
75    /// Type mismatch when adding sample to animated value.
76    #[cfg(feature = "builtin-types")]
77    #[error("cannot add `{got:?}` to animated `{expected:?}`")]
78    SampleTypeMismatch {
79        /// The expected data type.
80        expected: DataType,
81        /// The actual data type encountered.
82        got: DataType,
83    },
84
85    /// Cannot set interpolation on uniform value.
86    #[error("cannot set interpolation on uniform value")]
87    InterpolationOnUniform,
88
89    /// Bezier handles only supported for Real type.
90    #[cfg(feature = "builtin-types")]
91    #[error("bezier handles only supported for Real type, got `{got:?}`")]
92    BezierNotSupported {
93        /// The actual data type encountered.
94        got: DataType,
95    },
96
97    /// Sample trait called on wrong variant.
98    #[cfg(feature = "builtin-types")]
99    #[error("Sample<{sample_type}> called on `{got:?}` variant")]
100    SampleVariantMismatch {
101        /// The expected sample type.
102        sample_type: &'static str,
103        /// The actual data type encountered.
104        got: DataType,
105    },
106
107    /// Vector type cannot be empty.
108    #[error("{type_name} cannot be empty")]
109    EmptyVec {
110        /// The vector type name.
111        type_name: &'static str,
112    },
113
114    /// Key not found in data map.
115    #[error("key not found in data map")]
116    KeyNotFound,
117
118    /// Cannot extract value from animated data.
119    #[error("cannot extract {type_name} from animated Value")]
120    AnimatedExtraction {
121        /// The type name.
122        type_name: &'static str,
123    },
124
125    /// Type mismatch (generic version for custom data systems).
126    #[error("type mismatch: expected {expected}, got {got}")]
127    GenericTypeMismatch {
128        /// The expected type name.
129        expected: &'static str,
130        /// The actual type name.
131        got: &'static str,
132    },
133}
134
135/// Result type alias using the crate's [`Error`] type.
136pub type Result<T> = std::result::Result<T, Error>;