config_file2/
error.rs

1#[cfg(feature = "toml")]
2use toml_crate as toml;
3
4pub type Result<T> = std::result::Result<T, Error>;
5
6/// This type represents all possible errors that can occur when loading or
7/// storing data from a configuration file.
8#[derive(thiserror::Error, Debug)]
9pub enum Error {
10    /// There was an error while reading the configuration file
11    #[error("couldn't read or write config file")]
12    FileAccess(#[from] std::io::Error),
13
14    #[error("file already exists")]
15    FileExists,
16
17    /// There was an error while parsing the JSON data
18    #[cfg(feature = "json")]
19    #[error("couldn't parse JSON file")]
20    Json(#[from] serde_json::Error),
21
22    /// There was an error while parsing the TOML data
23    #[cfg(feature = "toml")]
24    #[error("couldn't parse TOML file")]
25    Toml(#[from] TomlError),
26
27    /// There was an error while parsing the XML data
28    #[cfg(feature = "xml")]
29    #[error("couldn't parse XML file")]
30    Xml(#[from] XmlError),
31
32    /// There was an error while parsing the YAML data
33    #[cfg(feature = "yaml")]
34    #[error("couldn't parse YAML file")]
35    Yaml(#[from] serde_yml::Error),
36
37    /// There was an error while parsing the Ron data
38    #[cfg(feature = "ron")]
39    #[error("couldn't parse Ron file")]
40    Ron(#[from] ron_crate::Error),
41
42    /// We don't know how to parse this format according to the file extension
43    #[error("don't know how to parse file")]
44    UnsupportedFormat,
45}
46
47/// Merge two TOML errors into one
48#[cfg(feature = "toml")]
49#[derive(Debug, thiserror::Error)]
50pub enum TomlError {
51    /// TOML deserialization error
52    #[error("Toml deserialization error: {0}")]
53    DeserializationError(#[from] toml::de::Error),
54
55    /// TOML serialization error
56    #[error("Toml serialization error: {0}")]
57    SerializationError(#[from] toml::ser::Error),
58}
59
60/// Merge two XML errors into one
61#[cfg(feature = "xml")]
62#[derive(Debug, thiserror::Error)]
63pub enum XmlError {
64    /// XML deserialization error
65    #[error("Xml deserialization error: {0}")]
66    DeserializationError(#[from] quick_xml::DeError),
67
68    /// XML serialization error
69    #[error("Xml serialization error: {0}")]
70    SerializationError(#[from] quick_xml::SeError),
71}