From 4dd7dba8d59f6b3bfd23bdb5c305ea6c9bebf3c8 Mon Sep 17 00:00:00 2001 From: pjht Date: Sun, 23 Oct 2022 17:26:57 -0500 Subject: [PATCH] Replace config file expects with anyhow --- src/main.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index a7202f4..599e262 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ use parse_int::parse; use peek::{PeekFormat, PeekSize}; use reedline_repl_rs::{ clap::{builder::BoolishValueParser, Arg, ArgAction, Command}, - Error as ReplError, Repl, + Repl, }; use serde::Deserialize; use serde_yaml::Mapping; @@ -57,9 +57,11 @@ struct EmuState { address_breakpoints: IndexSet, } -fn main() -> Result<(), ReplError> { - let config_str = fs::read_to_string("config.yaml").expect("Could not read config file"); - let config: EmuConfig = serde_yaml::from_str(&config_str).expect("Could not parse config file"); +fn main() -> Result<(), anyhow::Error> { + let config_str = fs::read_to_string("config.yaml") + .map_err(|e| anyhow!("Could not read config file ({})", e))?; + let config: EmuConfig = serde_yaml::from_str(&config_str) + .map_err(|e| anyhow!("Could not parse config file ({})", e))?; let mut backplane = Backplane::new(); for card in config.cards { match backplane.add_card(card.typ, &card.config) { @@ -444,7 +446,8 @@ fn main() -> Result<(), ReplError> { // Visible aliases don't actually work, so fake it with hidden subcommands .with_command(Command::new("q").hide(true), |_, _| process::exit(0)) .with_command(Command::new("exit").hide(true), |_, _| process::exit(0)) - .run() + .run()?; + Ok(()) } fn disas_fmt(