Skip to content
Snippets Groups Projects
Commit 0514221a authored by Franck Dary's avatar Franck Dary
Browse files

Added more detailed error messages and fixed invalid read in assert actions

parent 078e0446
No related branches found
No related tags found
No related merge requests found
......@@ -384,8 +384,18 @@ Action Action::assertIsEmpty(const std::string & colName, Config::Object object,
auto appliable = [colName, object, relativeIndex](const Config & config, const Action &)
{
auto lineIndex = config.getRelativeWordIndex(object, relativeIndex);
return util::isEmpty(config.getAsFeature(colName, lineIndex));
try
{
if (!config.hasRelativeWordIndex(object, relativeIndex))
return false;
auto lineIndex = config.getRelativeWordIndex(object, relativeIndex);
return util::isEmpty(config.getAsFeature(colName, lineIndex));
} catch (std::exception & e)
{
util::myThrow(fmt::format("colName='{}' object='{}' relativeIndex='{}' {}", colName, object == Config::Object::Stack ? "Stack" : "Buffer", relativeIndex, e.what()));
}
return false;
};
return {Type::Check, apply, undo, appliable};
......@@ -403,8 +413,18 @@ Action Action::assertIsNotEmpty(const std::string & colName, Config::Object obje
auto appliable = [colName, object, relativeIndex](const Config & config, const Action &)
{
auto lineIndex = config.getRelativeWordIndex(object, relativeIndex);
return !util::isEmpty(config.getAsFeature(colName, lineIndex));
try
{
if (!config.hasRelativeWordIndex(object, relativeIndex))
return false;
auto lineIndex = config.getRelativeWordIndex(object, relativeIndex);
return !util::isEmpty(config.getAsFeature(colName, lineIndex));
} catch (std::exception & e)
{
util::myThrow(fmt::format("colName='{}' object='{}' relativeIndex='{}' {}", colName, object == Config::Object::Stack ? "Stack" : "Buffer", relativeIndex, e.what()));
}
return false;
};
return {Type::Check, apply, undo, appliable};
......
......@@ -81,19 +81,28 @@ void Transition::apply(Config & config)
bool Transition::appliable(const Config & config) const
{
if (!state.empty() && state != config.getState())
return false;
for (const Action & action : sequence)
if (!action.appliable(config, action))
try
{
if (!state.empty() && state != config.getState())
return false;
for (const Action & action : sequence)
if (!action.appliable(config, action))
return false;
} catch (std::exception & e)
{
util::myThrow(fmt::format("transition '{}' {}", name, e.what()));
}
return true;
}
int Transition::getCost(const Config & config) const
{
return cost(config);
try {return cost(config);}
catch (std::exception & e) { util::myThrow(fmt::format("transition '{}' {}", name, e.what()));}
return 0;
}
const std::string & Transition::getName() const
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment