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    /// Type mismatch in animated samples.
49    #[cfg(feature = "builtin-types")]
50    #[error("animated sample type mismatch: expected `{expected:?}`, got `{got:?}` at time {time}")]
51    AnimatedTypeMismatch {
52        /// The expected data type.
53        expected: DataType,
54        /// The actual data type encountered.
55        got: DataType,
56        /// The time at which the mismatch occurred.
57        time: Time,
58    },
59
60    /// Vector length exceeds expected.
61    #[error("vector length {actual} exceeds expected {expected} at time {time}")]
62    VectorLengthExceeded {
63        /// The actual vector length.
64        actual: usize,
65        /// The expected maximum length.
66        expected: usize,
67        /// The time at which the error occurred.
68        time: Time,
69    },
70
71    /// Type mismatch when adding sample to animated value.
72    #[cfg(feature = "builtin-types")]
73    #[error("cannot add `{got:?}` to animated `{expected:?}`")]
74    SampleTypeMismatch {
75        /// The expected data type.
76        expected: DataType,
77        /// The actual data type encountered.
78        got: DataType,
79    },
80
81    /// Cannot set interpolation on uniform value.
82    #[error("cannot set interpolation on uniform value")]
83    InterpolationOnUniform,
84
85    /// Bezier handles only supported for Real type.
86    #[cfg(feature = "builtin-types")]
87    #[error("bezier handles only supported for Real type, got `{got:?}`")]
88    BezierNotSupported {
89        /// The actual data type encountered.
90        got: DataType,
91    },
92
93    /// Sample trait called on wrong variant.
94    #[cfg(feature = "builtin-types")]
95    #[error("Sample<{sample_type}> called on `{got:?}` variant")]
96    SampleVariantMismatch {
97        /// The expected sample type.
98        sample_type: &'static str,
99        /// The actual data type encountered.
100        got: DataType,
101    },
102
103    /// Vector type cannot be empty.
104    #[error("{type_name} cannot be empty")]
105    EmptyVec {
106        /// The vector type name.
107        type_name: &'static str,
108    },
109
110    /// Key not found in data map.
111    #[error("key not found in data map")]
112    KeyNotFound,
113
114    /// Cannot extract value from animated data.
115    #[error("cannot extract {type_name} from animated Value")]
116    AnimatedExtraction {
117        /// The type name.
118        type_name: &'static str,
119    },
120
121    /// Type mismatch (generic version for custom data systems).
122    #[error("type mismatch: expected {expected}, got {got}")]
123    GenericTypeMismatch {
124        /// The expected type name.
125        expected: &'static str,
126        /// The actual type name.
127        got: &'static str,
128    },
129}
130
131/// Result type alias using the crate's [`Error`] type.
132pub type Result<T> = std::result::Result<T, Error>;