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

index 2f1e782f4de30875728d0a834412c4e375f7f1a0..fde715bbbf1d14db2b40101053ce4ee12706f3a1 100644 (file)
@@ -43,7 +43,9 @@ TranslatorOptionData::getOptionDataKea(const string& xpath) {
     ConstElementPtr code = getItem(xpath + "/code");
     ConstElementPtr space = getItem(xpath + "/space");
     if (!code || !space) {
-        return (ElementPtr());
+        // Can't happen as code and space are the keys.
+        isc_throw(Unexpected, "getOptionDataKea requires code and space: "
+                  << xpath);
     }
     ElementPtr result = Element::createMap();
     result->set("code", code);
@@ -93,6 +95,7 @@ TranslatorOptionData::setOptionData(const string& xpath,
 void
 TranslatorOptionData::setOptionDataKea(const string& xpath,
                                        ConstElementPtr elem) {
+    // Skip keys code and space.
     ConstElementPtr name = elem->get("name");
     if (name) {
         setItem(xpath + "/name", name, SR_STRING_T);
@@ -146,7 +149,9 @@ TranslatorOptionDataList::getOptionDataListKea(const string& xpath) {
     ElementPtr result = Element::createList();
     S_Iter_Value iter = getIter(xpath + "/*");
     if (!iter) {
-        return (ConstElementPtr());
+        // Can't happen.
+        isc_throw(Unexpected, "getOptionDataListKea: can't get iterator: "
+                  << xpath);
     }
     for (;;) {
         const string& option = getNext(iter);
@@ -187,7 +192,7 @@ TranslatorOptionDataList::setOptionDataListKea(const string& xpath,
         }
         unsigned code = static_cast<unsigned>(option->get("code")->intValue());
         if (!option->contains("space")) {
-            isc_throw(BadValue,"option data without space: " <<option->str());
+            isc_throw(BadValue, "option data without space: " <<option->str());
         }
         string space = option->get("space")->stringValue();
         ostringstream keys;
index fdd3c88135cc314e9f84b342f1fe525fc167a583..e6530b9aa6fd1ddd1e3613f5653f6275a169b88f 100644 (file)
@@ -131,6 +131,7 @@ protected:
     ///
     /// @param xpath The xpath of the option data list.
     /// @param elem The JSON element.
+    /// @throw BadValue on option data without code or space.
     void setOptionDataListKea(const std::string& xpath,
                               isc::data::ConstElementPtr elem);