summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortaitep <taitep@taitep.se>2025-12-21 19:06:23 +0100
committertaitep <taitep@taitep.se>2025-12-21 19:06:23 +0100
commit944ed573c6f69e34c56179f98efd71b05e2bb02b (patch)
treea0058426e9a4d7fc4c9f0a26a6fe86f3627284b2 /src
parent2e1c0a7dce7b5ce225b7ac56897eff2c65acdaa7 (diff)
Switch the current binary to use anyhow errors and add a proper argument number check
Diffstat (limited to 'src')
-rw-r--r--src/main.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/main.rs b/src/main.rs
index 67186bb..5e20b1a 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -19,6 +19,8 @@ use trve::{
mem::{DeviceEntry, MemAccessFault, MemConfig, MemDeviceInterface, PageNum, Ram},
};
+use anyhow::{Result, bail};
+
use crate::basic_uart::BasicUart;
fn read_file_to_buffer(path: &str, buffer: &mut [u8]) -> io::Result<usize> {
@@ -41,14 +43,15 @@ fn read_file_to_buffer(path: &str, buffer: &mut [u8]) -> io::Result<usize> {
Ok(total_read)
}
-fn main() -> Result<(), Box<dyn Error>> {
+fn main() -> Result<()> {
let mut ram = Ram::try_new(16 * 1024 * 1024 / 4096)?;
let buf = ram.buf_mut();
let args: Vec<String> = env::args().collect();
if args.len() != 2 {
- eprintln!("USAGE: trve <ram_image>")
+ eprintln!("USAGE: trve <ram_image>");
+ bail!("Wrong number of arguments");
}
read_file_to_buffer(&args[1], buf)?;