Skip to main content

tinted_builder/
error.rs

1use ribboncurls::RibboncurlsError;
2use thiserror::Error;
3
4/// An error type representing the various errors that can occur when using tinted-builder
5///
6/// This error type is non-exhaustive, meaning additional variants may be added in future versions without
7/// it being considered a breaking change. The enum variants cover a range of possible issues that might
8/// arise during the processing of color schemes, including missing properties, deserialization errors,
9/// and rendering issues.
10#[non_exhaustive]
11#[derive(Error, Debug)]
12pub enum TintedBuilderError {
13    /// Error indicating that a required property in the scheme is missing.
14    ///
15    /// This variant is used when a necessary property for the scheme's configuration is not found.
16    #[error("missing scheme property: {0}")]
17    SchemeMissingProperty(String),
18
19    /// Error that occurs when YAML deserialization fails.
20    ///
21    /// This variant wraps the `serde_yaml::Error` and is used when there is an issue converting
22    /// a YAML string into the corresponding Rust data structure.
23    #[error("unable to deserialize yaml")]
24    YamlDeserialize(#[from] serde_yaml::Error),
25
26    /// Error that occurs during rendering using Ribboncurls.
27    ///
28    /// This variant wraps the `RibboncurlsError` and is used when an error is encountered while
29    /// rendering a template or other content using Ribboncurls.
30    #[error("unable to render")]
31    RibboncurlsRender(#[from] RibboncurlsError),
32
33    /// Error that occurs when a string slice cannot be converted to an integer with the given base.
34    ///
35    /// This variant wraps `std::num::ParseIntError` and is used when a string slice, such as a color
36    /// value in hexadecimal format, fails to parse correctly.
37    #[error("unable to convert string slice to integer with given base")]
38    ColorRadix(#[from] std::num::ParseIntError),
39
40    /// Error indicating that a hex color input is not formatted correctly.
41    ///
42    /// This variant is used when a color string that is expected to be in hex format does not match
43    /// the expected format.
44    #[error("hex input is not formatted correctly")]
45    HexInputFormat,
46
47    /// Error indicating that an invalid scheme variant was provided.
48    ///
49    /// This variant is used when an input string does not correspond to any valid scheme variant,
50    /// such as "dark" or "light".
51    #[error("invalid scheme variant: {0}")]
52    InvalidSchemeVariant(String),
53
54    /// Error indicating that an invalid scheme system was provided.
55    ///
56    /// This variant is used when an input string does not correspond to any valid scheme system
57    #[error("invalid scheme system: {0}")]
58    InvalidSchemeSystem(String),
59
60    /// Error indicating that an invalid color name was provided.
61    ///
62    /// This variant is used when an input string does not correspond to any valid color name.
63    #[error("invalid color name: {0}")]
64    InvalidColorName(String),
65
66    /// Error indicating that an invalid color variant was provided.
67    ///
68    /// This variant is used when an input string does not correspond to any valid color variant.
69    #[error("invalid color variant: {0}")]
70    InvalidColorVariant(String),
71
72    /// Error indicating that an invalid color type was provided.
73    ///
74    /// This variant is used when an input string does not correspond to a valid color type.
75    #[error("invalid color type: {0}")]
76    InvalidColorType(String),
77
78    /// Error indicating a `Color` conversion problem
79    ///
80    /// This variant is used when a color is not able to convert from one color to another
81    #[error("unable to convert Color from \"{0}\" to \"{1}\"")]
82    ColorConversion(String, String),
83
84    /// Error indicating an unsupported color derivation was requested.
85    ///
86    /// This variant is used when attempting to derive a color from another color
87    /// using an unsupported conversion path (e.g., deriving orange from blue).
88    #[error("unsupported color derivation: cannot derive {target} from {from_color} (supported: {supported_derivations})")]
89    UnsupportedColorDerivation {
90        from_color: String,
91        target: String,
92        supported_derivations: String,
93    },
94
95    /// Error indicating an inability to convert from type
96    ///
97    /// This variant is used when attempting to derive a color from another color
98    /// using an unsupported conversion path (e.g., deriving orange from blue).
99    #[error("unable to convert from type: {0}")]
100    UnableToConvertFrom(String),
101}