diff --git a/src/bus.rs b/src/bus.rs index 2400cfa..c8bea42 100644 --- a/src/bus.rs +++ b/src/bus.rs @@ -5,7 +5,7 @@ //! //! This is more of a memory management unit + some utils for reading/writing -use crate::error::Result; +use crate::error::{Error::MissingRegion, Result}; use std::{ fmt::{Debug, Display, Formatter}, ops::Range, @@ -319,9 +319,7 @@ impl Bus { } } } else { - return Err(crate::error::Error::MissingRegion { - region: REGION.to_string(), - }); + return Err(MissingRegion { region: REGION }); } Ok(()) } diff --git a/src/error.rs b/src/error.rs index bf0b197..c526107 100644 --- a/src/error.rs +++ b/src/error.rs @@ -3,6 +3,7 @@ //! Error type for Chirp +use crate::bus::Region; use thiserror::Error; pub type Result = std::result::Result; @@ -10,13 +11,15 @@ pub type Result = std::result::Result; #[derive(Debug, Error)] pub enum Error { #[error("Unrecognized opcode {word}")] - UnimplementedInstruction { word: u16 }, - #[error("Math was funky when parsing {word}: {explanation}")] - FunkyMath { word: u16, explanation: String }, + UnimplementedInstruction { + word: u16, + }, #[error("No {region} found on bus")] - MissingRegion { region: String }, + MissingRegion { + region: Region, + }, #[error(transparent)] IoError(#[from] std::io::Error), #[error(transparent)] - WindowError(#[from] minifb::Error), + MinifbError(#[from] minifb::Error), } diff --git a/tests/integration.rs b/tests/integration.rs index 2d7a6e0..6eff219 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -191,10 +191,8 @@ mod cpu { #[test] fn error() { - let error = chirp::error::Error::FunkyMath { - word: 0x1234, - explanation: "This shit was funky".to_owned(), - }; + let error = chirp::error::Error::MissingRegion { region: Screen }; + // Print it with Display and Debug println!("{error} {error:?}"); }