@@ -78,6 +78,21 @@ pub enum ConfigError {
78
78
key : Option < String > ,
79
79
} ,
80
80
81
+ /// Custom message
82
+ At {
83
+ /// Error being extended with a path
84
+ error : Box < ConfigError > ,
85
+
86
+ /// The URI that references the source that the value came from.
87
+ /// Example: `/path/to/config.json` or `Environment` or `etcd://localhost`
88
+ // TODO: Why is this called Origin but FileParse has a uri field?
89
+ origin : Option < String > ,
90
+
91
+ /// The key in the configuration hash of this value (if available where the
92
+ /// error is generated).
93
+ key : Option < String > ,
94
+ } ,
95
+
81
96
/// Custom message
82
97
Message ( String ) ,
83
98
@@ -130,7 +145,17 @@ impl ConfigError {
130
145
key : Some ( key. into ( ) ) ,
131
146
} ,
132
147
133
- _ => self ,
148
+ Self :: At { origin, error, .. } => Self :: At {
149
+ error,
150
+ origin,
151
+ key : Some ( key. into ( ) ) ,
152
+ } ,
153
+
154
+ other => Self :: At {
155
+ error : Box :: new ( other) ,
156
+ origin : None ,
157
+ key : Some ( key. into ( ) ) ,
158
+ } ,
134
159
}
135
160
}
136
161
@@ -157,8 +182,17 @@ impl ConfigError {
157
182
expected,
158
183
key : Some ( concat ( key) ) ,
159
184
} ,
185
+ Self :: At { error, origin, key } => Self :: At {
186
+ error,
187
+ origin,
188
+ key : Some ( concat ( key) ) ,
189
+ } ,
160
190
Self :: NotFound ( key) => Self :: NotFound ( concat ( Some ( key) ) ) ,
161
- _ => self ,
191
+ other => Self :: At {
192
+ error : Box :: new ( other) ,
193
+ origin : None ,
194
+ key : Some ( concat ( None ) ) ,
195
+ } ,
162
196
}
163
197
}
164
198
@@ -217,6 +251,24 @@ impl fmt::Display for ConfigError {
217
251
Ok ( ( ) )
218
252
}
219
253
254
+ ConfigError :: At {
255
+ ref error,
256
+ ref origin,
257
+ ref key,
258
+ } => {
259
+ write ! ( f, "{error}" ) ?;
260
+
261
+ if let Some ( ref key) = * key {
262
+ write ! ( f, " for key `{key}`" ) ?;
263
+ }
264
+
265
+ if let Some ( ref origin) = * origin {
266
+ write ! ( f, " in {origin}" ) ?;
267
+ }
268
+
269
+ Ok ( ( ) )
270
+ }
271
+
220
272
ConfigError :: FileParse { ref cause, ref uri } => {
221
273
write ! ( f, "{cause}" ) ?;
222
274
0 commit comments