[Fawkes Git] branch/vmatare/yamlconf-better-errors: created (0.5.0-2942-g6636bc7)

Victor Mataré matare at lih.rwth-aachen.de
Mon Jun 6 15:46:39 CEST 2016


Changes have been pushed for the project "Fawkes Robotics Software Framework".

Gitweb: http://git.fawkesrobotics.org/fawkes.git
Trac:   http://trac.fawkesrobotics.org

The branch, vmatare/yamlconf-better-errors has been created
        at  6636bc7d3b1655145c317a45c2cd1928d2f71fa1 (commit)

http://git.fawkesrobotics.org/fawkes.git/vmatare/yamlconf-better-errors

- *Log* ---------------------------------------------------------------
commit 6636bc7d3b1655145c317a45c2cd1928d2f71fa1
Author:     Victor Mataré <matare at lih.rwth-aachen.de>
AuthorDate: Thu Nov 19 16:48:24 2015 +0100
Commit:     Victor Mataré <matare at lih.rwth-aachen.de>
CommitDate: Thu Nov 19 16:48:24 2015 +0100

    config/yaml: add node path to exception message
    
    When a config value is rejected by the config parser because it doesn't
    match the hard-coded constraints for that value type, it may be
    difficult to find the responsible config file. With this, we output the
    full YAML path of the config value so the user can at least have a rough
    idea of where to look.

http://git.fawkesrobotics.org/fawkes.git/commit/6636bc7
http://trac.fawkesrobotics.org/changeset/6636bc7

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


- *Summary* -----------------------------------------------------------


- *Diffs* -------------------------------------------------------------

- *commit* 6636bc7d3b1655145c317a45c2cd1928d2f71fa1 - - - - - - - - - -
Author:  Victor Mataré <matare at lih.rwth-aachen.de>
Date:    Thu Nov 19 16:48:24 2015 +0100
Subject: config/yaml: add node path to exception message

 src/libs/config/yaml.cpp |   21 +++++++++++++--------
 src/libs/config/yaml.h   |    2 +-
 2 files changed, 14 insertions(+), 9 deletions(-)

_Diff for modified files_:
diff --git a/src/libs/config/yaml.cpp b/src/libs/config/yaml.cpp
index 0b2ecd2..2ce2214 100644
--- a/src/libs/config/yaml.cpp
+++ b/src/libs/config/yaml.cpp
@@ -752,12 +752,17 @@ YamlConfiguration::read_meta_doc(YAML::Node &doc, std::queue<LoadQueueEntry> &lo
 
 
 void
-YamlConfiguration::read_config_doc(const YAML::Node &doc, YamlConfigurationNode *&node)
+YamlConfiguration::read_config_doc(const YAML::Node &doc, YamlConfigurationNode *&node, std::string path)
 {
   if (! node) {
     node = new YamlConfigurationNode("root");
   }
 
+  if (*path.rbegin() != '/')
+    path += '/';
+  if (node->name() != "root")
+    path += node->name();
+
   if (doc.Type() == YAML::NodeType::Map) {
 #ifdef HAVE_YAMLCPP_0_5
     for (YAML::const_iterator it = doc.begin(); it != doc.end(); ++it) {
@@ -791,8 +796,8 @@ YamlConfiguration::read_config_doc(const YAML::Node &doc, YamlConfigurationNode
 	if (tmp->is_scalar() && it.second().Type() != YAML::NodeType::Scalar)
 #endif
 	{
-	  throw Exception("YamlConfig: scalar %s cannot be overwritten by non-scalar",
-			  tmp->name().c_str());
+	  throw Exception("YamlConfig: %s: scalar %s cannot be overwritten by non-scalar",
+			  path.c_str(), tmp->name().c_str());
 	}
 #ifdef HAVE_YAMLCPP_0_5
 	tmp->set_scalar(it->second.Scalar());
@@ -806,11 +811,11 @@ YamlConfiguration::read_config_doc(const YAML::Node &doc, YamlConfigurationNode
 #ifdef HAVE_YAMLCPP_0_5
 	YamlConfigurationNode *tmp = new YamlConfigurationNode(key, it->second);
 	in->add_child(key, tmp);
-	read_config_doc(it->second, tmp);
+	read_config_doc(it->second, tmp, path);
 #else
 	YamlConfigurationNode *tmp = new YamlConfigurationNode(key, it.second());
 	in->add_child(key, tmp);
-	read_config_doc(it.second(), tmp);
+	read_config_doc(it.second(), tmp, path);
 #endif
       }
     }
@@ -823,7 +828,7 @@ YamlConfiguration::read_config_doc(const YAML::Node &doc, YamlConfigurationNode
       try {
 	p = node->get_uint();
       } catch (Exception &e) {
-	e.prepend("YamlConfig: Invalid TCP/UDP port number (not an unsigned int)");
+	e.prepend("YamlConfig: %s: Invalid TCP/UDP port number (not an unsigned int)", path.c_str());
 	throw;
       }
       if (p <= 0 || p >= 65535) {
@@ -845,7 +850,7 @@ YamlConfiguration::read_config_doc(const YAML::Node &doc, YamlConfigurationNode
 #  endif
 #else
       if (regexec(&__url_regex, scalar.c_str(), 0, NULL, 0) == REG_NOMATCH) {
-	throw Exception("YamlConfig: %s is not a valid URL", scalar.c_str());
+	throw Exception("YamlConfig: %s: %s is not a valid URL", path.c_str(), scalar.c_str());
       }
 #endif
     } else if (doc.Tag() == "tag:fawkesrobotics.org,cfg/frame") {
@@ -863,7 +868,7 @@ YamlConfiguration::read_config_doc(const YAML::Node &doc, YamlConfigurationNode
 #  endif
 #else
       if (regexec(&__frame_regex, scalar.c_str(), 0, NULL, 0) == REG_NOMATCH) {
-	throw Exception("YamlConfig: %s is not a valid frame ID", scalar.c_str());
+	throw Exception("YamlConfig: %s: %s is not a valid frame ID", path.c_str(), scalar.c_str());
       }
 #endif
     }
diff --git a/src/libs/config/yaml.h b/src/libs/config/yaml.h
index 536c54c..924e64d 100644
--- a/src/libs/config/yaml.h
+++ b/src/libs/config/yaml.h
@@ -183,7 +183,7 @@ class YamlConfiguration
   YamlConfigurationNode *  query(const char *path) const;
   void read_meta_doc(YAML::Node &doc, std::queue<LoadQueueEntry> &load_queue,
                      std::string &host_file);
-  void read_config_doc(const YAML::Node &doc, YamlConfigurationNode *&node);
+  void read_config_doc(const YAML::Node &doc, YamlConfigurationNode *&node, std::string path = "");
   YamlConfigurationNode * read_yaml_file(std::string filename, bool ignore_missing,
 			std::queue<LoadQueueEntry> &load_queue, std::string &host_file);
   void read_yaml_config(std::string filename, std::string &host_file,




-- 
Fawkes Robotics Framework                 http://www.fawkesrobotics.org


More information about the fawkes-commits mailing list