Skip to content

Commit

Permalink
feat(core): change not to panic
Browse files Browse the repository at this point in the history
Try to get them to report errors instead of panicking.
  • Loading branch information
SARDONYX-sard committed Jan 19, 2024
1 parent 3767e22 commit 1ea96a2
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions dar2oar_core/src/condition_parser/conditions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::conditions::{
IsWornHasKeyword, Level, Or, RandomCondition,
};
use crate::dar_syntax::syntax::{self, Expression};
use crate::values::{Cmp, DirectionValue, NumericValue};
use crate::values::{Cmp, DirectionValue};

pub fn parse_conditions(input: syntax::Condition) -> Result<ConditionSet, ParseError> {
Ok(match input {
Expand Down Expand Up @@ -50,7 +50,7 @@ fn parse_condition(condition: Expression<'_>) -> Result<ConditionSet, ParseError
"CurrentGameTimeLessThan" => ConditionSet::CurrentGameTime(CurrentGameTime {
negated,
comparison: Cmp::Lt,
numeric_value: NumericValue::StaticValue(args[0].clone().try_into().unwrap()),
numeric_value: args.try_get(0, "NumericValue for CurrentGameTime")?.into(),
..Default::default()
}),
"CurrentWeather" => gen_cond!(
Expand All @@ -75,7 +75,7 @@ fn parse_condition(condition: Expression<'_>) -> Result<ConditionSet, ParseError
"IsLevelLessThan" => ConditionSet::Level(Level {
negated,
comparison: Cmp::Lt,
numeric_value: args.try_get(0, "NumericValue")?.into(),
numeric_value: args.try_get(0, "NumericValue for Level")?.into(),
..Default::default()
}),
"IsParentCell" => gen_cond!(
Expand Down
4 changes: 2 additions & 2 deletions dar2oar_core/src/values/type_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ impl TryFrom<NumericLiteral> for WeaponType {
fn try_from(value: NumericLiteral) -> Result<Self, Self::Error> {
match value {
NumericLiteral::Hex(num) => match num {
1..=18 => Ok((num as i64).try_into().expect("unreachable")),
1..=18 => Ok((num as i64).try_into()?),
_ => Err("Got hex, Out of range 1..=18"),
},
NumericLiteral::Decimal(num) => match num {
-1..=18 => Ok((num as i64).try_into().expect("unreachable")),
-1..=18 => Ok((num as i64).try_into()?),
_ => Err("Got Decimal, Out of range -1..=18"),
},
NumericLiteral::Float(num) => Ok(num.to_string().as_str().try_into()?),
Expand Down

0 comments on commit 1ea96a2

Please sign in to comment.