hocon_rs/
error.rs

1use std::fmt::Display;
2
3#[derive(Debug, thiserror::Error)]
4pub enum Error {
5    #[error("{0}")]
6    Io(#[from] std::io::Error),
7    #[error("{0}")]
8    Serde(#[from] serde_json::Error),
9    #[error("Invalid escape")]
10    InvalidEscape,
11    #[error(
12        "Unexpected token, expected:{}, found beginning:{}",
13        expected,
14        found_beginning
15    )]
16    UnexpectedToken {
17        expected: &'static str,
18        found_beginning: char,
19    },
20    #[error("End of file")]
21    Eof,
22    #[error("Cannot convert `{from}` to `{to}`")]
23    InvalidConversion {
24        from: &'static str,
25        to: &'static str,
26    },
27    #[error("Invalid path expression: {0}")]
28    InvalidPathExpression(&'static str),
29    #[error("Cannot concatenate different type {left_type} and {right_type} at {path}")]
30    ConcatenateDifferentType {
31        path: String,
32        left_type: &'static str,
33        right_type: &'static str,
34    },
35    #[error("{val} is not allowed in {ty}")]
36    InvalidValue { val: &'static str, ty: &'static str },
37    #[error("Invalid concat, values_len:{0} == spaces_len:{1} + 1")]
38    InvalidConcat(usize, usize),
39    #[error("Substitution {0} not found")]
40    SubstitutionNotFound(String),
41    #[error(
42        "Resolve incomplete. This should never happen outside this library. If you see this, it's a bug."
43    )]
44    ResolveIncomplete,
45    #[error("Circular include detected")]
46    InclusionCycle,
47    #[error("Object nesting depth exceeded the limit of {max_depth} levels")]
48    RecursionDepthExceeded { max_depth: usize },
49    #[error("Inclusion: {inclusion} error: {error}")]
50    Include {
51        inclusion: String,
52        error: Box<Error>,
53    },
54    #[error(
55    "Substitution cycle: {} -> {current} (cycle closed)",
56    backtrace.join(" -> ")
57    )]
58    SubstitutionCycle {
59        current: String,
60        backtrace: Vec<String>,
61    },
62    #[error("substitution depth exceeded the limit of {max_depth} levels")]
63    SubstitutionDepthExceeded { max_depth: usize },
64    #[error("{0}")]
65    DeserializeError(String),
66    #[error("{0}")]
67    JavaProperties(#[from] java_properties::PropertiesError),
68    #[error("{0}")]
69    UrlParseError(#[from] url::ParseError),
70    #[cfg(not(feature = "urls_includes"))]
71    #[error(
72        "Cannot include URL-based config: the 'urls_includes' feature is not enabled. Add 'features = [\"urls_includes\"]' to your dependency declaration"
73    )]
74    UrlsIncludesDisabled,
75}
76
77impl serde::de::Error for Error {
78    #[doc = r" Raised when there is general error when deserializing a type."]
79    #[doc = r""]
80    #[doc = r" The message should not be capitalized and should not end with a period."]
81    #[doc = r""]
82    #[doc = r" ```edition2021"]
83    #[doc = r" # use std::str::FromStr;"]
84    #[doc = r" #"]
85    #[doc = r" # struct IpAddr;"]
86    #[doc = r" #"]
87    #[doc = r" # impl FromStr for IpAddr {"]
88    #[doc = r" #     type Err = String;"]
89    #[doc = r" #"]
90    #[doc = r" #     fn from_str(_: &str) -> Result<Self, String> {"]
91    #[doc = r" #         unimplemented!()"]
92    #[doc = r" #     }"]
93    #[doc = r" # }"]
94    #[doc = r" #"]
95    #[doc = r" use serde::de::{self, Deserialize, Deserializer};"]
96    #[doc = r""]
97    #[doc = r" impl<'de> Deserialize<'de> for IpAddr {"]
98    #[doc = r"     fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>"]
99    #[doc = r"     where"]
100    #[doc = r"         D: Deserializer<'de>,"]
101    #[doc = r"     {"]
102    #[doc = r"         let s = String::deserialize(deserializer)?;"]
103    #[doc = r"         s.parse().map_err(de::Error::custom)"]
104    #[doc = r"     }"]
105    #[doc = r" }"]
106    #[doc = r" ```"]
107    fn custom<T>(msg: T) -> Self
108    where
109        T: Display,
110    {
111        Self::DeserializeError(msg.to_string())
112    }
113}