Skip to content

Commit

Permalink
Add check for expected keys to TaskComposerGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Jul 19, 2024
1 parent a328986 commit 4cabf56
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions tesseract_task_composer/core/src/task_composer_graph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <yaml-cpp/yaml.h>
#include <tesseract_common/serialization.h>
#include <tesseract_common/plugin_info.h>
#include <tesseract_common/yaml_utils.h>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_task_composer/core/task_composer_graph.h>
Expand Down Expand Up @@ -70,13 +71,20 @@ TaskComposerGraph::TaskComposerGraph(std::string name,
const TaskComposerPluginFactory& plugin_factory)
: TaskComposerNode(std::move(name), type, TaskComposerNodePorts{}, config)
{
static const std::set<std::string> graph_expected_keys{ "conditional", "inputs", "outputs",
"nodes", "edges", "terminals" };
tesseract_common::checkForUnknownKeys(config, graph_expected_keys);

std::unordered_map<std::string, boost::uuids::uuid> node_uuids;
YAML::Node nodes = config["nodes"];
if (!nodes.IsMap())
throw std::runtime_error("Task Composer Graph '" + name_ + "' 'nodes' entry is not a map");

for (auto node_it = nodes.begin(); node_it != nodes.end(); ++node_it)
{
static const std::set<std::string> nodes_expected_keys{ "class", "task", "config" };
tesseract_common::checkForUnknownKeys(node_it->second, nodes_expected_keys);

auto node_name = node_it->first.as<std::string>();
if (YAML::Node fn = node_it->second["class"])
{
Expand All @@ -103,6 +111,9 @@ TaskComposerGraph::TaskComposerGraph(std::string name,

if (YAML::Node tc = node_it->second["config"])
{
static const std::set<std::string> tasks_expected_keys{ "conditional", "abort_terminal", "remapping" };
tesseract_common::checkForUnknownKeys(tc, tasks_expected_keys);

if (YAML::Node n = tc["conditional"])
task_node->setConditional(n.as<bool>());

Expand All @@ -115,12 +126,6 @@ TaskComposerGraph::TaskComposerGraph(std::string name,
throw std::runtime_error("YAML entry 'abort_terminal' is only supported for GRAPH and PIPELINE types");
}

if (tc["input_remapping"]) // NOLINT
throw std::runtime_error("TaskComposerGraph, input_remapping is no longer supported use 'remapping'");

if (tc["output_remapping"]) // NOLINT
throw std::runtime_error("TaskComposerGraph, output_remapping is no longer supported use 'remapping'");

if (YAML::Node n = tc["remapping"])
{
auto remapping = n.as<std::map<std::string, std::string>>();
Expand Down

0 comments on commit 4cabf56

Please sign in to comment.