From: Ian Jackson Date: Sun, 8 Aug 2021 14:06:17 +0000 (+0100) Subject: config; Better contexts for errors X-Git-Tag: hippotat/1.0.0~218 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=2384e781ef580efebef75100b427f37ba56da5ad;p=hippotat.git config; Better contexts for errors Signed-off-by: Ian Jackson --- diff --git a/src/config.rs b/src/config.rs index 56abf1d..93cc168 100644 --- a/src/config.rs +++ b/src/config.rs @@ -254,19 +254,22 @@ impl Aggregate { let sn = sn.parse().dcontext(&sn)?; let vars = §ion.values; - for key in vars.keys() { - let skl = if key == "server" { - SKL::ServerName - } else { - *self.keys_allowed.get(key.as_str()).ok_or_else( - || anyhow!("unknown configuration key {:?}", key) - )? - }; - if ! skl.contains(&sn, self.end) { - throw!(anyhow!( - "configuration key {:?} not applicable in this kind of section: {}", - key, &sn)) - } + for (key, val) in vars { + (||{ + let skl = if key == "server" { + SKL::ServerName + } else { + *self.keys_allowed.get(key.as_str()).ok_or_else( + || anyhow!("unknown configuration key") + )? + }; + if ! skl.contains(&sn, self.end) { + throw!(anyhow!("key not applicable in this kind of section")) + } + Ok::<_,AE>(()) + })() + .with_context(|| format!("key {:?}", key)) + .with_context(|| val.loc.to_string())? } let ent = self.sections.entry(sn) @@ -299,7 +302,7 @@ impl Aggregate { Ok::<_,AE>(unq) })() .with_context(|| format!("key {:?}", key)) - .dcontext(path_for_loc)? + .with_context(|| loc.to_string())? } else { raw.clone() };