From: Francis Dupont Date: Sat, 22 Sep 2018 15:16:00 +0000 (+0200) Subject: [65-libyang-option-def] Added Unexpected for impossible conditions and @throw for... X-Git-Tag: 65-libyang-class_base^2^2~6^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a08b91ccb9c6e6eefbc71278ef797f7bf5724001;p=thirdparty%2Fkea.git [65-libyang-option-def] Added Unexpected for impossible conditions and @throw for BadValue --- diff --git a/src/lib/yang/translator_option_def.cc b/src/lib/yang/translator_option_def.cc index ddc53ccd8f..4161b1d588 100644 --- a/src/lib/yang/translator_option_def.cc +++ b/src/lib/yang/translator_option_def.cc @@ -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); diff --git a/src/lib/yang/translator_option_def.h b/src/lib/yang/translator_option_def.h index 6faa089d20..068d280131 100644 --- a/src/lib/yang/translator_option_def.h +++ b/src/lib/yang/translator_option_def.h @@ -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);