Skip to main content

hocon/
error.rs

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