Error: Remove FunkyMathError and Stringly Typed context
This commit is contained in:
parent
9195d439e3
commit
c194a3c53a
@ -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(())
|
||||
}
|
||||
|
13
src/error.rs
13
src/error.rs
@ -3,6 +3,7 @@
|
||||
|
||||
//! Error type for Chirp
|
||||
|
||||
use crate::bus::Region;
|
||||
use thiserror::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)]
|
||||
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),
|
||||
}
|
||||
|
@ -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:?}");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user