aboutsummaryrefslogtreecommitdiff
path: root/crates/readrom/src/main.rs
diff options
context:
space:
mode:
authorMiquel Sabaté Solà <mikisabate@gmail.com>2025-01-10 21:55:13 +0100
committerMiquel Sabaté Solà <mikisabate@gmail.com>2025-01-10 21:55:13 +0100
commit23b4fcf9bc5933c0370f74b61a6c2db2d4a0ac78 (patch)
tree197baf849fd3dd740508e5bfd02dd1b5cc79d4cd /crates/readrom/src/main.rs
parentc20c991dded87e22f6cb657cc52a0a80ea23f902 (diff)
downloadtools.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/src/main.rs')
-rw-r--r--crates/readrom/src/main.rs25
1 files changed, 17 insertions, 8 deletions
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(())
}