chiark / gitweb /
shapelib: Introduce and use LLE::InLibrary
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 May 2022 20:28:45 +0000 (21:28 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 May 2022 23:19:17 +0000 (00:19 +0100)
Otherwise bundle errors are really quite inscrutable.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/shapelib.rs

index a150ed024391d24298eb937c1adb47a76978d046..a1317daff2cd9ec4515ddc52275e6aaa19e95fdd 100644 (file)
@@ -135,6 +135,9 @@ pub enum LibraryLoadError {
   #[error("{0}")] UnsupportedColourSpec(#[from] UnsupportedColourSpec),
   #[error("bad item name (invalid characters) in {0:?}")] BadItemName(String),
   #[error("{0:?}")] MaterialsFormatVersionError(#[from] MFVE),
+
+  #[error("library {lib}: {error}")]
+  InLibrary { lib: String, error: Box<LLE> },
 }
 
 #[derive(Error,Debug,Clone,Copy,Serialize,Deserialize)]
@@ -860,6 +863,8 @@ impl LibrarySource for BuiltinLibrary<'_> {
 #[throws(LibraryLoadError)]
 pub fn load_catalogue(libname: &str, src: &mut dyn LibrarySource)
                       -> Catalogue {
+  (||{
+
   let toplevel: toml::Value = src.catalogue_data().parse()?;
   let toplevel = toplevel
     .as_table().ok_or_else(|| LLE::ExpectedTable(format!("toplevel")))?;
@@ -1028,7 +1033,11 @@ pub fn load_catalogue(libname: &str, src: &mut dyn LibrarySource)
       }
     }
   }
-  l
+
+  Ok(l)
+  })().map_err(
+    |error| LLE::InLibrary { lib: libname.into(), error: Box::new(error) }
+  )?
 }
 
 //---------- reading, support functions ----------