From: Ian Jackson Date: Wed, 11 May 2022 20:28:45 +0000 (+0100) Subject: shapelib: Introduce and use LLE::InLibrary X-Git-Tag: otter-1.1.0~237 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=1243b82c721fe0975987d25b78ea3a785628a5aa;p=otter.git shapelib: Introduce and use LLE::InLibrary Otherwise bundle errors are really quite inscrutable. Signed-off-by: Ian Jackson --- diff --git a/src/shapelib.rs b/src/shapelib.rs index a150ed02..a1317daf 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -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 }, } #[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 ----------