From: Ian Jackson Date: Wed, 19 May 2021 23:42:46 +0000 (+0100) Subject: specs: Change error handling for load_spec_to_read X-Git-Tag: otter-0.6.0~136 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c783eb1142f5dccda27c4d15c1ae8c530bf5531e;p=otter.git specs: Change error handling for load_spec_to_read Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 3ad736b8..02d76f4a 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -693,14 +693,12 @@ fn execute_game_insn<'cs, 'igr, 'ig: 'igr>( MGI::ResetFromNamedSpec { spec } => { reset_game_from_spec(cs,ag,ig,who, Box::new(move |ig| { - let (mut spec_f, what) = bundles::load_spec_to_read(ig,&spec)?; + let (mut spec_f, e_f) = bundles::load_spec_to_read(ig,&spec)?; let mut buf = String::new(); spec_f.read_to_string(&mut buf).map_err(|e| match e.kind() { ErrorKind::InvalidData => ME::GameSpecInvalidData, ErrorKind::UnexpectedEof => ME::BadBundle(e.to_string()), - _ => IE::from( - AE::from(e).context(what).context("read spec") - ).into() + _ => e_f(e), })?; Ok::<_,ME>(buf) }))? diff --git a/src/bundles.rs b/src/bundles.rs index 30a9b755..726720e6 100644 --- a/src/bundles.rs +++ b/src/bundles.rs @@ -711,9 +711,10 @@ fn make_usvg(za: &mut IndexedZip, progress_count: &mut usize, //---------- specs ---------- #[throws(MgmtError)] -pub fn load_spec_to_read(ig: &Instance, spec_name: &str) - -> (Box, String) -{ +pub fn load_spec_to_read(ig: &Instance, spec_name: &str) -> ( + Box, + Box MgmtError> +) { let spec_leaf = format!("{}.game.toml", spec_name); // todo: game specs from bundles @@ -725,7 +726,12 @@ pub fn load_spec_to_read(ig: &Instance, spec_name: &str) debug!("{}: trying to loading builtin spec from {}", &ig.name, &path); match File::open(&path) { - Ok(f) => return (Box::new(f) as _, path), + Ok(f) => return ( + Box::new(f) as _, + Box::new(move |e| IE::from( + AE::from(e).context(path.clone()).context("read spec") + ).into()) as _, + ), Err(e) if e.kind() == ErrorKind::NotFound => { }, Err(e) => throw!(IE::from( AE::from(e).context(path).context("try open game spec")