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

index 4cc8733416614e0ad0772d9d316d4280451bc3ff..dfbf23df9df81e48b5435303ae5b90adfc9d6189 100644 (file)
@@ -41,7 +41,9 @@ ElementPtr
 TranslatorDatabase::getDatabaseKea(const string& xpath) {
     ConstElementPtr type = getItem(xpath + "/database-type");
     if (!type) {
-        return (ElementPtr());
+        // Can't happen as database-type is the key.
+        isc_throw(Unexpected, "getDatabaseKea requires database-type: "
+                  << xpath);
     }
     ElementPtr result = Element::createMap();
     result->set("type", type);
@@ -146,7 +148,8 @@ TranslatorDatabase::setDatabaseKea(const string& xpath,
     if (!skip) {
         ConstElementPtr type = elem->get("type");
         if (!type) {
-            isc_throw(BadValue, "setDatabase missing database type");
+            isc_throw(BadValue, "setDatabase requires database type: "
+                      << elem->str());
         }
         setItem(xpath + "/database-type", type, SR_STRING_T);
     }
@@ -251,7 +254,8 @@ ElementPtr
 TranslatorDatabases::getDatabasesKea(const string& xpath) {
     S_Iter_Value iter = getIter(xpath + "/*");
     if (!iter) {
-        return (ElementPtr());
+        // Can't happen.
+        isc_throw(Unexpected, "getDatabasesKea can't get iterator: " << xpath);
     }
     ElementPtr result = Element::createList();
     for (;;) {
index 25454d425a6ac277cbed7d6aae1ca12582c2b0f7..6c91c9484322b9e30493d1a09bbd002b8b051cc2 100644 (file)
@@ -110,6 +110,7 @@ protected:
     /// @param xpath The xpath of the database access.
     /// @param elem The JSON element.
     /// @param skip The skip type field flag.
+    /// @throw BadValue on database without tyoe,
     void setDatabaseKea(const std::string& xpath,
                         isc::data::ConstElementPtr elem,
                         bool skip);
@@ -165,6 +166,7 @@ protected:
     ///
     /// @param xpath The xpath of databases.
     /// @param elem The JSON element.
+    /// @throw BadValue on database without tyoe,
     void setDatabasesKea(const std::string& xpath,
                          isc::data::ConstElementPtr elem);