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("Include nesting depth exceeded the limit of {max_depth} levels")]
50 InclusionDepthExceeded { max_depth: usize },
51 #[error("Object nesting depth exceeded the limit of {max_depth} levels")]
52 RecursionDepthExceeded { max_depth: usize },
53 #[error("Inclusion: {inclusion} error: {error}")]
54 Include {
55 inclusion: String,
56 error: Box<Error>,
57 },
58 #[error(
59 "Substitution cycle: {} -> {current} (cycle closed)",
60 backtrace.join(" -> ")
61 )]
62 SubstitutionCycle {
63 current: String,
64 backtrace: Vec<String>,
65 },
66 #[error("Substitution depth exceeded the limit of {max_depth} levels")]
67 SubstitutionDepthExceeded { max_depth: usize },
68 #[error("{0}")]
69 Deserialize(String),
70 #[cfg(feature = "properties")]
71 #[error("{0}")]
72 JavaProperties(#[from] java_properties::PropertiesError),
73 #[cfg(not(feature = "properties"))]
74 #[error(
75 "Cannot load Java properties: the 'properties' feature is not enabled. Add 'features = [\"properties\"]' to your dependency declaration"
76 )]
77 PropertiesDisabled,
78 #[error("{0}")]
79 UrlParse(#[from] url::ParseError),
80 #[error("Invalid file URL: {0}")]
81 InvalidFileUrl(String),
82 #[cfg(feature = "urls_includes")]
83 #[error("{0}")]
84 Http(#[from] reqwest::Error),
85 #[cfg(not(feature = "urls_includes"))]
86 #[error(
87 "Cannot include URL-based config: the 'urls_includes' feature is not enabled. Add 'features = [\"urls_includes\"]' to your dependency declaration"
88 )]
89 UrlsIncludesDisabled,
90}
91
92impl serde::de::Error for Error {
93 #[doc = r" Raised when there is general error when deserializing a type."]
94 #[doc = r""]
95 #[doc = r" The message should not be capitalized and should not end with a period."]
96 #[doc = r""]
97 #[doc = r" ```edition2021"]
98 #[doc = r" # use std::str::FromStr;"]
99 #[doc = r" #"]
100 #[doc = r" # struct IpAddr;"]
101 #[doc = r" #"]
102 #[doc = r" # impl FromStr for IpAddr {"]
103 #[doc = r" # type Err = String;"]
104 #[doc = r" #"]
105 #[doc = r" # fn from_str(_: &str) -> Result<Self, String> {"]
106 #[doc = r" # unimplemented!()"]
107 #[doc = r" # }"]
108 #[doc = r" # }"]
109 #[doc = r" #"]
110 #[doc = r" use serde::de::{self, Deserialize, Deserializer};"]
111 #[doc = r""]
112 #[doc = r" impl<'de> Deserialize<'de> for IpAddr {"]
113 #[doc = r" fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>"]
114 #[doc = r" where"]
115 #[doc = r" D: Deserializer<'de>,"]
116 #[doc = r" {"]
117 #[doc = r" let s = String::deserialize(deserializer)?;"]
118 #[doc = r" s.parse().map_err(de::Error::custom)"]
119 #[doc = r" }"]
120 #[doc = r" }"]
121 #[doc = r" ```"]
122 fn custom<T>(msg: T) -> Self
123 where
124 T: Display,
125 {
126 Self::Deserialize(msg.to_string())
127 }
128}