]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[65-libyang-option-def] Added Unexpected for impossible conditions and @throw for...
authorFrancis Dupont <fdupont@isc.org>
Sat, 22 Sep 2018 15:16:00 +0000 (17:16 +0200)
committerFrancis Dupont <fdupont@isc.org>
Sat, 22 Sep 2018 15:16:00 +0000 (17:16 +0200)
src/lib/yang/translator_option_def.cc
src/lib/yang/translator_option_def.h

index ddc53ccd8f7693a504656c86a6e2a3c9d576df55..4161b1d5880cb7192ad03ce10a3f4acead58058f 100644 (file)
@@ -44,8 +44,14 @@ TranslatorOptionDef::getOptionDefKea(const string& xpath) {
     ConstElementPtr name = getItem(xpath + "/name");
     ConstElementPtr type = getItem(xpath + "/type");
     ConstElementPtr space = getItem(xpath + "/space");
-    if (!code || !name || !type || !space) {
-        return (ElementPtr());
+    if (!code || !space) {
+       // Can't happen as code and space are the keys.
+       isc_throw(Unexpected, "getOptionDefKea requires code and space: "
+                 << xpath);
+    }
+    if (!name || !type) {
+       isc_throw(BadValue, "getOptionDefKea requires name and type: "
+                 << xpath);
     }
     ElementPtr result = Element::createMap();
     result->set("code", code);
@@ -92,6 +98,7 @@ TranslatorOptionDef::setOptionDef(const string& xpath, ConstElementPtr elem) {
 void
 TranslatorOptionDef::setOptionDefKea(const string& xpath,
                                      ConstElementPtr elem) {
+    // Skip code and space as they are the keys.
     ConstElementPtr name = elem->get("name");
     if (!name) {
         isc_throw(BadValue, "option definition with name: " << elem->str());
@@ -151,7 +158,9 @@ TranslatorOptionDefList::getOptionDefListKea(const string& xpath) {
     ElementPtr result = Element::createList();
     S_Iter_Value iter = getIter(xpath + "/*");
     if (!iter) {
-        return (ConstElementPtr());
+        // Can't happen.
+        isc_throw(Unexpected, "getOptionDefListKea: can't get iterator: "
+                  << xpath);
     }
     for (;;) {
         const string& def = getNext(iter);
index 6faa089d207f19a7867f6471db6193d369405ba4..068d280131248213bd4e7ebc937949597ba0bdb0 100644 (file)
@@ -78,12 +78,14 @@ protected:
     /// @param xpath The xpath of the option definition.
     /// @return JSON representation of the option definition.
     /// @throw SysrepoError when sysrepo raises an error.
+    /// @throw BadValue on option definition without name or type.
     isc::data::ElementPtr getOptionDefKea(const std::string& xpath);
 
     /// @brief setOptionDef for kea-dhcp[46].
     ///
     /// @param xpath The xpath of the option definition.
     /// @param elem The JSON element.
+    /// @throw BadValue on option definition without name or type.
     void setOptionDefKea(const std::string& xpath,
                          isc::data::ConstElementPtr elem);
 
@@ -135,6 +137,7 @@ protected:
     ///
     /// @param xpath The xpath of the option definition list.
     /// @param elem The JSON element.
+    /// @throw BadValue on option definition without code or space.
     void setOptionDefListKea(const std::string& xpath,
                              isc::data::ConstElementPtr elem);