hocon_linked/
error.rs

1use thiserror::Error;
2
3/// Errors that can be encountered while reading a HOCON document
4#[derive(Error, Debug, Clone, PartialEq)]
5pub enum Error {
6    /// Captures IO-Errors. Usually we would use a transparent error but io::Error is not clonable
7    #[error("Error during IO")]
8    Io {
9        /// the description of the original IOError
10        message: String,
11    },
12
13    /// Error reading a file. This can be a file not found, a permission issue, ...
14    #[error("Error reading file '{path:?}'")]
15    File {
16        /// Path to the file being read
17        path: String,
18    },
19    /// Error while parsing a document. The document is not valid HOCON
20    #[error("Error wile parsing document")]
21    Parse,
22    /// Error including a document
23    #[error("Error including document at '{path:?}'")]
24    Include {
25        /// Path of the included file
26        path: String,
27    },
28    /// Error processing deep includes. You can change the maximum depth using max_include_depth
29    #[error("Error processing deep includes")]
30    TooManyIncludes,
31    /// Error processing includes from a str source. This is not allowed
32    #[error("Error processing includes from a str source")]
33    IncludeNotAllowedFromStr,
34    /// Error including document with External URL as feature has been disabled
35    #[error("Error including document with External URL as feature has been disabled")]
36    DisabledExternalUrl,
37    /// Error looking for a key
38    #[error("Error looking for key '{key:?}'")]
39    KeyNotFound {
40        /// Key that was searched
41        key: String,
42    },
43    /// Error getting a value because key is not present
44    #[error("Error getting a value because key is not present")]
45    MissingKey,
46    /// Error getting a value because of an invalid key type
47    #[error("Error getting a value because of an invalid key type")]
48    InvalidKey,
49    /// Error deserializing
50    #[error("Error deserializing: {message:?}")]
51    Deserialization {
52        /// Error message returned from deserialization
53        message: String,
54    },
55}
56
57/// this is only needed because this crate heavily relies on Clone and io:Error doesnt implement Clone
58impl From<std::io::Error> for Error {
59    fn from(e: std::io::Error) -> Self {
60        Error::Io {
61            message: e.to_string(),
62        }
63    }
64}