Commit 373ef178 authored by Jelte Jansen's avatar Jelte Jansen

[1857] make ModuleSpecError derive from isc::Exception

parent e0cb5ab6
...@@ -40,13 +40,14 @@ check_leaf_item(ConstElementPtr spec, const std::string& name, ...@@ -40,13 +40,14 @@ check_leaf_item(ConstElementPtr spec, const std::string& name,
if (spec->get(name)->getType() == type) { if (spec->get(name)->getType() == type) {
return; return;
} else { } else {
throw ModuleSpecError(name + " not of type " + Element::typeToName(type)); isc_throw(ModuleSpecError,
name + " not of type " + Element::typeToName(type));
} }
} else if (mandatory) { } else if (mandatory) {
// todo: want parent item name, and perhaps some info about location // todo: want parent item name, and perhaps some info about location
// in list? or just catch and throw new... // in list? or just catch and throw new...
// or make this part non-throwing and check return value... // or make this part non-throwing and check return value...
throw ModuleSpecError(name + " missing in " + spec->str()); isc_throw(ModuleSpecError, name + " missing in " + spec->str());
} }
} }
...@@ -80,7 +81,7 @@ check_config_item(ConstElementPtr spec) { ...@@ -80,7 +81,7 @@ check_config_item(ConstElementPtr spec) {
void void
check_config_item_list(ConstElementPtr spec) { check_config_item_list(ConstElementPtr spec) {
if (spec->getType() != Element::list) { if (spec->getType() != Element::list) {
throw ModuleSpecError("config_data is not a list of elements"); isc_throw(ModuleSpecError, "config_data is not a list of elements");
} }
BOOST_FOREACH(ConstElementPtr item, spec->listValue()) { BOOST_FOREACH(ConstElementPtr item, spec->listValue()) {
check_config_item(item); check_config_item(item);
...@@ -122,7 +123,7 @@ void check_statistics_item_list(ConstElementPtr spec); ...@@ -122,7 +123,7 @@ void check_statistics_item_list(ConstElementPtr spec);
void void
check_statistics_item_list(ConstElementPtr spec) { check_statistics_item_list(ConstElementPtr spec) {
if (spec->getType() != Element::list) { if (spec->getType() != Element::list) {
throw ModuleSpecError("statistics is not a list of elements"); isc_throw(ModuleSpecError, "statistics is not a list of elements");
} }
BOOST_FOREACH(ConstElementPtr item, spec->listValue()) { BOOST_FOREACH(ConstElementPtr item, spec->listValue()) {
check_config_item(item); check_config_item(item);
...@@ -135,7 +136,7 @@ check_statistics_item_list(ConstElementPtr spec) { ...@@ -135,7 +136,7 @@ check_statistics_item_list(ConstElementPtr spec) {
&& item->contains("item_default")) { && item->contains("item_default")) {
if(!check_format(item->get("item_default"), if(!check_format(item->get("item_default"),
item->get("item_format"))) { item->get("item_format"))) {
throw ModuleSpecError( isc_throw(ModuleSpecError,
"item_default not valid type of item_format"); "item_default not valid type of item_format");
} }
} }
...@@ -152,7 +153,7 @@ check_command(ConstElementPtr spec) { ...@@ -152,7 +153,7 @@ check_command(ConstElementPtr spec) {
void void
check_command_list(ConstElementPtr spec) { check_command_list(ConstElementPtr spec) {
if (spec->getType() != Element::list) { if (spec->getType() != Element::list) {
throw ModuleSpecError("commands is not a list of elements"); isc_throw(ModuleSpecError, "commands is not a list of elements");
} }
BOOST_FOREACH(ConstElementPtr item, spec->listValue()) { BOOST_FOREACH(ConstElementPtr item, spec->listValue()) {
check_command(item); check_command(item);
...@@ -183,7 +184,7 @@ check_module_specification(ConstElementPtr def) { ...@@ -183,7 +184,7 @@ check_module_specification(ConstElementPtr def) {
try { try {
check_data_specification(def); check_data_specification(def);
} catch (const TypeError& te) { } catch (const TypeError& te) {
throw ModuleSpecError(te.what()); isc_throw(ModuleSpecError, te.what());
} }
} }
} }
...@@ -314,14 +315,14 @@ moduleSpecFromFile(const std::string& file_name, const bool check) ...@@ -314,14 +315,14 @@ moduleSpecFromFile(const std::string& file_name, const bool check)
if (!file) { if (!file) {
std::stringstream errs; std::stringstream errs;
errs << "Error opening " << file_name << ": " << strerror(errno); errs << "Error opening " << file_name << ": " << strerror(errno);
throw ModuleSpecError(errs.str()); isc_throw(ModuleSpecError, errs.str());
} }
ConstElementPtr module_spec_element = Element::fromJSON(file, file_name); ConstElementPtr module_spec_element = Element::fromJSON(file, file_name);
if (module_spec_element->contains("module_spec")) { if (module_spec_element->contains("module_spec")) {
return (ModuleSpec(module_spec_element->get("module_spec"), check)); return (ModuleSpec(module_spec_element->get("module_spec"), check));
} else { } else {
throw ModuleSpecError("No module_spec in specification"); isc_throw(ModuleSpecError, "No module_spec in specification");
} }
} }
...@@ -333,7 +334,7 @@ moduleSpecFromFile(std::ifstream& in, const bool check) ...@@ -333,7 +334,7 @@ moduleSpecFromFile(std::ifstream& in, const bool check)
if (module_spec_element->contains("module_spec")) { if (module_spec_element->contains("module_spec")) {
return (ModuleSpec(module_spec_element->get("module_spec"), check)); return (ModuleSpec(module_spec_element->get("module_spec"), check));
} else { } else {
throw ModuleSpecError("No module_spec in specification"); isc_throw(ModuleSpecError, "No module_spec in specification");
} }
} }
......
...@@ -26,15 +26,11 @@ namespace isc { namespace config { ...@@ -26,15 +26,11 @@ namespace isc { namespace config {
/// A standard ModuleSpec exception that is thrown when a /// A standard ModuleSpec exception that is thrown when a
/// specification is not in the correct form. /// specification is not in the correct form.
/// ///
/// TODO: use jinmei's exception class as a base and not c_str in class ModuleSpecError : public isc::Exception {
/// what() there
class ModuleSpecError : public std::exception {
public: public:
ModuleSpecError(std::string m = "Module specification is invalid") : msg(m) {} ModuleSpecError(const char* file, size_t line,
~ModuleSpecError() throw() {} const char* what = "Module specification is invalid") :
const char* what() const throw() { return (msg.c_str()); } isc::Exception(file, line, what) {}
private:
std::string msg;
}; };
/// ///
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment