Error: Remove FunkyMathError and Stringly Typed context

This commit is contained in:
John 2023-03-29 23:42:41 -05:00
parent 9195d439e3
commit c194a3c53a
3 changed files with 12 additions and 13 deletions

View File

@ -5,7 +5,7 @@
//! //!
//! This is more of a memory management unit + some utils for reading/writing //! 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::{ use std::{
fmt::{Debug, Display, Formatter}, fmt::{Debug, Display, Formatter},
ops::Range, ops::Range,
@ -319,9 +319,7 @@ impl Bus {
} }
} }
} else { } else {
return Err(crate::error::Error::MissingRegion { return Err(MissingRegion { region: REGION });
region: REGION.to_string(),
});
} }
Ok(()) Ok(())
} }

View File

@ -3,6 +3,7 @@
//! Error type for Chirp //! Error type for Chirp
use crate::bus::Region;
use thiserror::Error; use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;
@ -10,13 +11,15 @@ pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, Error)] #[derive(Debug, Error)]
pub enum Error { pub enum Error {
#[error("Unrecognized opcode {word}")] #[error("Unrecognized opcode {word}")]
UnimplementedInstruction { word: u16 }, UnimplementedInstruction {
#[error("Math was funky when parsing {word}: {explanation}")] word: u16,
FunkyMath { word: u16, explanation: String }, },
#[error("No {region} found on bus")] #[error("No {region} found on bus")]
MissingRegion { region: String }, MissingRegion {
region: Region,
},
#[error(transparent)] #[error(transparent)]
IoError(#[from] std::io::Error), IoError(#[from] std::io::Error),
#[error(transparent)] #[error(transparent)]
WindowError(#[from] minifb::Error), MinifbError(#[from] minifb::Error),
} }

View File

@ -191,10 +191,8 @@ mod cpu {
#[test] #[test]
fn error() { fn error() {
let error = chirp::error::Error::FunkyMath { let error = chirp::error::Error::MissingRegion { region: Screen };
word: 0x1234, // Print it with Display and Debug
explanation: "This shit was funky".to_owned(),
};
println!("{error} {error:?}"); println!("{error} {error:?}");
} }