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