From 23b4fcf9bc5933c0370f74b61a6c2db2d4a0ac78 Mon Sep 17 00:00:00 2001 From: Miquel Sabaté Solà Date: Fri, 10 Jan 2025 21:55:13 +0100 Subject: Remove anyhow from xa65 and readrom MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Following in the footsteps of c20c991dded8 ("Make errors from nasm itself more cohesive"), 'anyhow' might provide an easy framework, but it lends towards a less cohesive experience. Signed-off-by: Miquel Sabaté Solà --- crates/readrom/src/main.rs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'crates/readrom/src/main.rs') diff --git a/crates/readrom/src/main.rs b/crates/readrom/src/main.rs index 56e60e0..32e648b 100644 --- a/crates/readrom/src/main.rs +++ b/crates/readrom/src/main.rs @@ -1,4 +1,3 @@ -use anyhow::{bail, Result}; use clap::Parser as ClapParser; use header::{Header, Kind}; use std::fs::File; @@ -33,23 +32,33 @@ fn print_header(header: &Header) { println!(" Mapper:\t{}", header.mapper); } -fn main() -> Result<()> { +// Print the given `message` and exit(1). +fn die(message: String) { + println!("{}", message); + std::process::exit(1); +} + +fn main() { let args = Args::parse(); - let mut input = File::open(args.file)?; + let Ok(mut input) = File::open(&args.file) else { + die(format!("failed to open the given file '{}'", &args.file)); + return; + }; let mut buf = vec![0u8; 0x10]; if let Err(e) = input.read_exact(&mut buf) { match e.kind() { - ErrorKind::UnexpectedEof => bail!("malformed ROM file."), - _ => return Err(e.into()), + ErrorKind::UnexpectedEof => die("malformed ROM file".to_string()), + _ => die(e.to_string()), } } let header = match Header::try_from(buf.as_slice()) { Ok(h) => h, - Err(e) => bail!("{}.", e), + Err(e) => { + die(e.to_string()); + return; + } }; print_header(&header); - - Ok(()) } -- cgit v1.2.3