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)
}))?
//---------- specs ----------
#[throws(MgmtError)]
-pub fn load_spec_to_read(ig: &Instance, spec_name: &str)
- -> (Box<dyn Read>, String)
-{
+pub fn load_spec_to_read(ig: &Instance, spec_name: &str) -> (
+ Box<dyn Read>,
+ Box<dyn FnOnce(io::Error) -> MgmtError>
+) {
let spec_leaf = format!("{}.game.toml", spec_name);
// todo: game specs from bundles
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")