diff options
| author | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-10 21:55:13 +0100 |
|---|---|---|
| committer | Miquel Sabaté Solà <mikisabate@gmail.com> | 2025-01-10 21:55:13 +0100 |
| commit | 23b4fcf9bc5933c0370f74b61a6c2db2d4a0ac78 (patch) | |
| tree | 197baf849fd3dd740508e5bfd02dd1b5cc79d4cd /crates/readrom | |
| parent | c20c991dded87e22f6cb657cc52a0a80ea23f902 (diff) | |
| download | tools.nes-23b4fcf9bc5933c0370f74b61a6c2db2d4a0ac78.tar.gz tools.nes-23b4fcf9bc5933c0370f74b61a6c2db2d4a0ac78.zip | |
Remove anyhow from xa65 and readrom
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à <mikisabate@gmail.com>
Diffstat (limited to 'crates/readrom')
| -rw-r--r-- | crates/readrom/Cargo.toml | 1 | ||||
| -rw-r--r-- | crates/readrom/src/main.rs | 25 |
2 files changed, 17 insertions, 9 deletions
diff --git a/crates/readrom/Cargo.toml b/crates/readrom/Cargo.toml index 98a5106..68ca68c 100644 --- a/crates/readrom/Cargo.toml +++ b/crates/readrom/Cargo.toml @@ -7,6 +7,5 @@ license.workspace = true authors.workspace = true [dependencies] -anyhow = "^1" clap = { version = "^4", features = ["derive"] } header.workspace = true 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(()) } |
