proper error handling v2 (does not compile for now)
This commit is contained in:
parent
7570f39402
commit
0c7f30a73d
3 changed files with 37 additions and 48 deletions
31
src/errorfr/mod.rs
Normal file
31
src/errorfr/mod.rs
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
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,
|
||||||
|
|
||||||
|
/// 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. "
|
||||||
|
)]
|
||||||
|
JsonCorrupt,
|
||||||
|
|
||||||
|
/// 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,
|
||||||
|
|
||||||
|
/// 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,
|
||||||
|
|
||||||
|
/// 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. ")]
|
||||||
|
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. ")]
|
||||||
|
ShinyJsonCorrupt
|
||||||
|
}
|
|
@ -1,43 +0,0 @@
|
||||||
/// Potential errors thrown during encoding of id strings
|
|
||||||
#[derive(Error, Debug)]
|
|
||||||
pub enum EncodeError {
|
|
||||||
/// Encoder was given a string with non ascii characters.
|
|
||||||
#[error("Cannot encode non ascii string")]
|
|
||||||
NonAsciiString,
|
|
||||||
|
|
||||||
/// More than 255 identifications were passed for encoding
|
|
||||||
#[error("Cannot encode more than 255 identifications per item")]
|
|
||||||
TooManyIdentifications,
|
|
||||||
/// Identification is missing a basevalue while using the extended encoding scheme.
|
|
||||||
///
|
|
||||||
/// An id is required to have an basevalue if the extended encoding is used for idents
|
|
||||||
#[error("Identification id: {0} was not given a base value while using extended encoding")]
|
|
||||||
NoBasevalueGiven(u8),
|
|
||||||
|
|
||||||
/// More than 255 powders were passed for encoding
|
|
||||||
#[error("Cannot encode more than 255 powders per item")]
|
|
||||||
TooManyPowders,
|
|
||||||
/// Invalid tier for a powder was passed
|
|
||||||
#[error("Invalid powder tier of {0} was passed")]
|
|
||||||
InvalidPowderTier(u8),
|
|
||||||
|
|
||||||
/// Effect strength should be a percentage between 0 and 100
|
|
||||||
#[error("Effect strength of {0} is too high, it should be a percentage between 0 and 100")]
|
|
||||||
EffectStrengthTooHigh(u8),
|
|
||||||
|
|
||||||
/// More than 255 skills were passed for encoding
|
|
||||||
#[error("Cannot encode more than 255 skills per item")]
|
|
||||||
TooManySkills,
|
|
||||||
|
|
||||||
/// More than 255 damage values were passed for encoding
|
|
||||||
#[error("Cannot encode more than 255 damage values per item")]
|
|
||||||
TooManyDamageValues,
|
|
||||||
|
|
||||||
/// More than 255 effects were passed for encoding
|
|
||||||
#[error("Cannot encode more than 255 effects per item")]
|
|
||||||
TooManyEffects,
|
|
||||||
|
|
||||||
/// More than 255 defense values were passed for encoding
|
|
||||||
#[error("Cannot encode more than 255 defense values per item")]
|
|
||||||
TooManyDefences,
|
|
||||||
}
|
|
11
src/main.rs
11
src/main.rs
|
@ -12,8 +12,8 @@ use std::fs;
|
||||||
use std::panic;
|
use std::panic;
|
||||||
mod structures;
|
mod structures;
|
||||||
use crate::structures::*;
|
use crate::structures::*;
|
||||||
mod errors;
|
mod errorfr;
|
||||||
|
use crate::errorfr::Errorfr;
|
||||||
|
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
|
@ -31,7 +31,7 @@ struct Args {
|
||||||
|
|
||||||
// const fallbackconfigpath: String = "config.json".to_owned();
|
// const fallbackconfigpath: String = "config.json".to_owned();
|
||||||
|
|
||||||
fn main() {
|
fn main() -> Result<(), Errors> {
|
||||||
// enable fancypanic when building for release
|
// enable fancypanic when building for release
|
||||||
// fancypanic();
|
// fancypanic();
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
@ -47,8 +47,9 @@ fn main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newest json reading code
|
// newest json reading code
|
||||||
let json_config: Jsonconfig =
|
let json_config: Jsonconfig = serde_json::from_reader(fs::File::open(configpath)
|
||||||
serde_json::from_reader(fs::File::open(configpath).expect(ERROR[1])).expect(ERROR[2]);
|
.map_err(|_| Errorfr::JsonMissing)?)
|
||||||
|
.map_err(|_| Errorfr::JsonCorrupt)?;
|
||||||
let idsmap: HashMap<String, u8> =
|
let idsmap: HashMap<String, u8> =
|
||||||
serde_json::from_reader(fs::File::open("id_keys.json").expect(ERROR[3])).expect(ERROR[4]);
|
serde_json::from_reader(fs::File::open("id_keys.json").expect(ERROR[3])).expect(ERROR[4]);
|
||||||
let json_shiny: Vec<Shinystruct> =
|
let json_shiny: Vec<Shinystruct> =
|
||||||
|
|
Loading…
Reference in a new issue