mirror of
https://github.com/loot/libloot.git
synced 2026-07-27 14:16:01 -07:00
Remove condition_eval_fail error code
Throw a ConditionSyntaxError if parsing doesn't throw but fails or is incomplete, and propagate all other exceptions.
This commit is contained in:
@@ -46,11 +46,6 @@ public:
|
||||
* failed, but its failure was not fatal to the task being performed.
|
||||
*/
|
||||
ok = 0,
|
||||
/**
|
||||
* An error was encountered when attempting to evaluate a metadata
|
||||
* condition.
|
||||
*/
|
||||
condition_eval_fail = 4,
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -82,20 +82,21 @@ bool ConditionalMetadata::ParseCondition(Game * game) const {
|
||||
begin = condition_.begin();
|
||||
end = condition_.end();
|
||||
|
||||
bool r;
|
||||
bool eval;
|
||||
try {
|
||||
r = boost::spirit::qi::phrase_parse(begin, end, grammar, skipper, eval);
|
||||
bool evaluation;
|
||||
bool parseResult = boost::spirit::qi::phrase_parse(begin, end, grammar, skipper, evaluation);
|
||||
|
||||
if (!parseResult || begin != end) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to parse condition \"" << condition_ << "\": only partially matched expected syntax.";
|
||||
throw ConditionSyntaxError((boost::format(translate("Failed to parse condition \"%1%\": only partially matched expected syntax.")) % condition_).str());
|
||||
}
|
||||
|
||||
return evaluation;
|
||||
} catch (ConditionSyntaxError& e) {
|
||||
throw;
|
||||
} catch (exception& e) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to parse condition \"" << condition_ << "\": " << e.what();
|
||||
throw Error(Error::Code::condition_eval_fail, (boost::format(translate("Failed to parse condition \"%1%\": %2%")) % condition_ % e.what()).str());
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to evaluate condition \"" << condition_ << "\": " << e.what();
|
||||
throw;
|
||||
}
|
||||
|
||||
if (!r || begin != end) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Failed to parse condition \"" << condition_ << "\".";
|
||||
throw Error(Error::Code::condition_eval_fail, (boost::format(translate("Failed to parse condition \"%1%\".")) % condition_).str());
|
||||
}
|
||||
|
||||
return eval;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,7 +80,7 @@ TEST_P(ConditionalMetadataTest, evalConditionShouldThrowForAnInvalidCondition) {
|
||||
game.SetGamePath(dataPath.parent_path());
|
||||
|
||||
conditionalMetadata_ = ConditionalMetadata("condition");
|
||||
EXPECT_THROW(conditionalMetadata_.EvalCondition(game), Error);
|
||||
EXPECT_THROW(conditionalMetadata_.EvalCondition(game), ConditionSyntaxError);
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, evalConditionShouldReturnTrueForAConditionThatIsTrue) {
|
||||
@@ -105,7 +105,7 @@ TEST_P(ConditionalMetadataTest, parseConditionShouldNotThrowForAnEmptyCondition)
|
||||
|
||||
TEST_P(ConditionalMetadataTest, parseConditionShouldThrowForAnInvalidCondition) {
|
||||
conditionalMetadata_ = ConditionalMetadata("condition");
|
||||
EXPECT_THROW(conditionalMetadata_.ParseCondition(), Error);
|
||||
EXPECT_THROW(conditionalMetadata_.ParseCondition(), ConditionSyntaxError);
|
||||
}
|
||||
|
||||
TEST_P(ConditionalMetadataTest, parseConditionShouldNotThrowForATrueCondition) {
|
||||
|
||||
Reference in New Issue
Block a user