@@ -78,6 +78,16 @@ pub enum ConfigError {
7878 key : Option < String > ,
7979 } ,
8080
81+ /// Custom message
82+ At {
83+ /// Error being extended with a path
84+ error : Box < ConfigError > ,
85+
86+ /// The key in the configuration hash of this value (if available where the
87+ /// error is generated).
88+ key : Option < String > ,
89+ } ,
90+
8191 /// Custom message
8292 Message ( String ) ,
8393
@@ -130,7 +140,15 @@ impl ConfigError {
130140 key : Some ( key. into ( ) ) ,
131141 } ,
132142
133- _ => self ,
143+ Self :: At { error, .. } => Self :: At {
144+ error,
145+ key : Some ( key. into ( ) ) ,
146+ } ,
147+
148+ other => Self :: At {
149+ error : Box :: new ( other) ,
150+ key : Some ( key. into ( ) ) ,
151+ } ,
134152 }
135153 }
136154
@@ -157,8 +175,15 @@ impl ConfigError {
157175 expected,
158176 key : Some ( concat ( key) ) ,
159177 } ,
178+ Self :: At { error, key } => Self :: At {
179+ error,
180+ key : Some ( concat ( key) ) ,
181+ } ,
160182 Self :: NotFound ( key) => Self :: NotFound ( concat ( Some ( key) ) ) ,
161- _ => self ,
183+ other => Self :: At {
184+ error : Box :: new ( other) ,
185+ key : Some ( concat ( None ) ) ,
186+ } ,
162187 }
163188 }
164189
@@ -217,6 +242,16 @@ impl fmt::Display for ConfigError {
217242 Ok ( ( ) )
218243 }
219244
245+ ConfigError :: At { ref error, ref key } => {
246+ write ! ( f, "{error}" ) ?;
247+
248+ if let Some ( ref key) = * key {
249+ write ! ( f, " for key `{key}`" ) ?;
250+ }
251+
252+ Ok ( ( ) )
253+ }
254+
220255 ConfigError :: FileParse { ref cause, ref uri } => {
221256 write ! ( f, "{cause}" ) ?;
222257
0 commit comments