Commit aa98039a authored by Alessio Netti's avatar Alessio Netti
Browse files

DA: error checking and logging

- Checking for invalid sensor names in SensorNavigator auto build mode
- More meaningful logging when failing to build sensor trees
parent e2c8026a
......@@ -6,7 +6,7 @@
const string SensorNavigator::rootKey = "__root__";
const string SensorNavigator::templateKey = "__template__";
const string SensorNavigator::pathSeparator = ".";
const char SensorNavigator::pathSeparator = '.';
void SensorNavigator::clearTree() {
if(_sensorTree) {
......@@ -339,6 +339,11 @@ void SensorNavigator::_addAutoSensor(const string& name, const string& topic) {
size_t sepPos = -1;
int d=0;
if(name.empty() || name[0] == pathSeparator || name[name.size()-1] == pathSeparator) {
clearTree();
throw invalid_argument("SensorNavigator: sensor " + name + " does not describe a valid tree path!");
}
//We verify how deep in the hierarchy the input sensor is by searching for the appropriate path separators
while((sepPos = name.find(pathSeparator, sepPos+1)) != std::string::npos) {
//prev contains the name of the parent for the current node in the subtree
......
......@@ -31,7 +31,7 @@ public:
//Template identifier
static const string templateKey;
//Separator for tree levels used in auto mode
static const string pathSeparator;
static const char pathSeparator;
//Internal structure to store nodes
struct Node {
......
......@@ -397,6 +397,7 @@ int main(int argc, char** argv) {
try {
navigator->buildTree(globalSettings.hierarchy, &names, &topics);
} catch(const std::invalid_argument& e) {
LOG(error) << e.what();
LOG(error) << "Failed to build sensor hierarchy tree, data analytics manager will not be initialized!";
failedTree = true;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment