From: Francis Dupont Date: Sun, 29 Jan 2017 10:51:26 +0000 (+0100) Subject: [5126] Improved SimpleParser getPosition X-Git-Tag: trac5124a_base~26^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca4a11ca0bf6a2f2c9c5ada94304fd14d4f9710c;p=thirdparty%2Fkea.git [5126] Improved SimpleParser getPosition --- diff --git a/src/lib/cc/simple_parser.cc b/src/lib/cc/simple_parser.cc index 6e6dfd26a4..c66cf9a1a4 100644 --- a/src/lib/cc/simple_parser.cc +++ b/src/lib/cc/simple_parser.cc @@ -74,7 +74,7 @@ SimpleParser::getPosition(const std::string& name, const data::ConstElementPtr p } ConstElementPtr elem = parent->get(name); if (!elem) { - return (data::Element::ZERO_POSITION()); + return (parent->getPosition()); } return (elem->getPosition()); } diff --git a/src/lib/cc/simple_parser.h b/src/lib/cc/simple_parser.h index a7352a5ed3..524449806e 100644 --- a/src/lib/cc/simple_parser.h +++ b/src/lib/cc/simple_parser.h @@ -104,9 +104,9 @@ class SimpleParser { /// @brief Utility method that returns position of an element /// - /// It's mostly useful for logging. When any necessary parameter is - /// missing (either parent is null or it doesn't contain specified - /// name) ZERO_POSITION is returned. + /// It's mostly useful for logging. If the element is missing + /// the parent position is returned or ZERO_POSITION if parent + /// is null. /// /// @param name position of that element will be returned /// @param parent parent element (optional) diff --git a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc index e085c5443a..ad0d6de711 100644 --- a/src/lib/dhcpsrv/parsers/dhcp_parsers.cc +++ b/src/lib/dhcpsrv/parsers/dhcp_parsers.cc @@ -430,10 +430,7 @@ OptionDataParser::extractSpace(ConstElementPtr parent) const { } } catch (std::exception& ex) { - // Append position of the option space parameter. Note, that in the case - // when 'space' was not specified a default value will be used and we - // should never get here. Therefore, it is ok to call getPosition for - // the space parameter here as this parameter will always be specified. + // Append position of the option space parameter. isc_throw(DhcpConfigError, ex.what() << " (" << getPosition("space", parent) << ")"); } @@ -1046,17 +1043,10 @@ SubnetConfigParser::createSubnet(ConstElementPtr params) { try { std::string hr_mode = getString(params, "reservation-mode"); subnet_->setHostReservationMode(hrModeFromText(hr_mode)); - } catch (const BadValue& ex) { - ConstElementPtr mode = params->get("reservation-mode"); - string pos; - if (mode) { - pos = mode->getPosition().str(); - } else { - pos = params->getPosition().str(); - } - isc_throw(DhcpConfigError, "Failed to process specified value " + } catch (const BadValue& ex) { + isc_throw(DhcpConfigError, "Failed to process specified value " " of reservation-mode parameter: " << ex.what() - << "(" << pos << ")"); + << "(" << getPosition("reservation-mode", params) << ")"); } // Try setting up client class.