chiark / gitweb /
config; Better contexts for errors
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 14:06:17 +0000 (15:06 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 Aug 2021 14:06:17 +0000 (15:06 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/config.rs

index 56abf1d7086e90459e458ba8d25d8a39660c733e..93cc168eb8cef74c7cc9823813f59f5c8370d310 100644 (file)
@@ -254,19 +254,22 @@ impl Aggregate {
       let sn = sn.parse().dcontext(&sn)?;
       let vars = &section.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()
         };