finally, proper error handling support

This commit is contained in:
endernon 2024-11-05 19:17:45 +00:00
parent e1cbcfc193
commit c1cca55db7
2 changed files with 28 additions and 25 deletions

View file

@ -3,29 +3,28 @@ use thiserror::Error;
/// Errors yep
#[derive(Error, Debug)]
pub enum Errorfr {
/// config json is missing
#[error("Error 1: json config json is missing, obtain it from https://git.frfrnocap.men/endernon/idmangler-cli/raw/branch/main/config.json and move it to this directory. "
)]
JsonMissing,
/// item config json is missing
#[error("Error 1: item config json is missing")]
ItemJsonMissing,
/// config json is corrupt
#[error("Error 2: json config json is corrupt. Reread config.md or reobtain it from https://git.frfrnocap.men/endernon/idmangler-cli/raw/branch/main/config.json and move it to this diirectory. "
/// item config json is corrupt
#[error("Error 2: item config json is corrupt, Reread config.md"
)]
JsonCorrupt,
ItemJsonCorrupt,
/// idmap is missing
#[error("Error 3: Identifications hashmap is missing. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory. ")]
IDMapMissing,
#[error("Error 3: Identifications hashmap is missing")]
IDMapJsonMissing,
/// idmap is corrupt
#[error("Error 4: Identifications hashmap is corrupt. Reobtain it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Reference/id_keys.json and move it to this directory. ")]
IDMapCorrupt,
#[error("Error 4: Identifications hashmap is corrupt")]
IDMapJsonCorrupt,
/// shiny data json is missing
#[error("Error 5: Shiny data json is missing. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json and move it to this directory. ")]
#[error("Error 5: shiny_stats.json is missing.")]
ShinyJsonMissing,
/// shiny data json is corrupt
#[error("Error 6: Shiny data json is corrupt. Get it from https://raw.githubusercontent.com/Wynntils/Static-Storage/main/Data-Storage/shiny_stats.json and move it to this directory. ")]
#[error("Error 6: shiny_stats.json is corrupt.")]
ShinyJsonCorrupt
}

View file

@ -31,11 +31,12 @@ struct Args {
// const fallbackconfigpath: String = "config.json".to_owned();
#[derive(Debug)]
struct E;
fn main() -> Result<(), E> {
fn main() {
if let Err(e) = cook() {
println!("{}",e);
}
}
fn cook() -> Result<(), Errorfr> {
// enable fancypanic when building for release
// fancypanic();
let args = Args::parse();
@ -52,13 +53,14 @@ fn main() -> Result<(), E> {
// newest json reading code
let json_config: Jsonconfig = serde_json::from_reader(fs::File::open(configpath)
.map_err(|_| Errorfr::JsonMissing)?)
.map_err(|_| Errorfr::JsonCorrupt)?;
let idsmap: HashMap<String, u8> =
serde_json::from_reader(fs::File::open("id_keys.json").expect(ERROR[3])).expect(ERROR[4]);
let json_shiny: Vec<Shinystruct> =
serde_json::from_reader(fs::File::open("shiny_stats.json").expect(ERROR[5]))
.expect(ERROR[6]);
.map_err(|_| Errorfr::ItemJsonMissing)?)
.map_err(|_| Errorfr::ItemJsonCorrupt)?;
let idsmap: HashMap<String, u8> = serde_json::from_reader(fs::File::open("id_keys.json")
.map_err(|_| Errorfr::IDMapJsonMissing)?)
.map_err(|_| Errorfr::IDMapJsonCorrupt)?;
let json_shiny: Vec<Shinystruct> = serde_json::from_reader(fs::File::open("shiny_stats.json")
.map_err(|_| Errorfr::ShinyJsonMissing)?)
.map_err(|_| Errorfr::ShinyJsonCorrupt)?;
// println!("{:?}",idsmap.get("airDamage"));
let mut out = Vec::new();
@ -243,6 +245,8 @@ fn main() -> Result<(), E> {
//let out = decode(&mut bytes_iter).unwrap();
// println!("{:#?}", out);
Ok(())
}
fn fancypanic() {