Browse Source

[1253] update docs and add safeguard catch

Jelte Jansen 13 years ago
parent
commit
2a2aa4ccfb

+ 8 - 3
src/lib/datasrc/factory.cc

@@ -71,9 +71,14 @@ DataSourceClientContainer::DataSourceClientContainer(const std::string& type,
     destructor_ = (ds_destructor*)ds_lib_.getSym("destroyInstance");
 
     std::string error;
-    instance_ = ds_create(config, error);
-    if (instance_ == NULL) {
-        isc_throw(DataSourceError, error);
+    try {
+        instance_ = ds_create(config, error);
+        if (instance_ == NULL) {
+            isc_throw(DataSourceError, error);
+        }
+    } catch (const std::exception& exc) {
+        isc_throw(DataSourceError, "Unknown uncaugt exception from " + type +
+                                   " createInstance" + exc.what());
     }
 }
 

+ 3 - 2
src/lib/datasrc/factory.h

@@ -133,8 +133,9 @@ public:
     ///            backend library
     /// \exception DataSourceLibrarySymbolError if the library does not have
     ///            the needed symbols, or if there is an error reading them
-    /// \exception DataSourceConfigError if the given config is not correct
-    ///            for the given type
+    /// \exception DataError if the given config is not correct
+    ///            for the given type, or if there was a problem during
+    ///            initialization
     ///
     /// \param type The type of the datasource client. Based on the value of
     ///             type, a specific backend library is used, by appending the

+ 6 - 1
src/lib/datasrc/memory_datasrc.cc

@@ -937,7 +937,12 @@ createInstance(isc::data::ConstElementPtr config, std::string& error) {
         error = "Configuration error: " + errors->str();
         return (NULL);
     }
-    return (new InMemoryClient());
+    try {
+        return (new InMemoryClient());
+    } catch (const std::exception& exc) {
+        error = std::string("Error creating memory datasource: ") + exc.what();
+        return (NULL);
+    }
 }
 
 void destroyInstance(DataSourceClient* instance) {

+ 6 - 0
src/lib/datasrc/memory_datasrc.h

@@ -310,6 +310,12 @@ private:
 ///
 /// This configuration setup is currently under discussion and will change in
 /// the near future.
+///
+/// \param config The configuration for the datasource instance
+/// \param error This string will be set to an error message if an error occurs
+///              during initialization
+/// \return An instance of the memory datasource client, or NULL if there was
+///         an error
 extern "C" DataSourceClient* createInstance(isc::data::ConstElementPtr config,
                                             std::string& error);
 

+ 2 - 2
src/lib/datasrc/sqlite3_accessor.cc

@@ -763,7 +763,7 @@ DataSourceClient *
 createInstance(isc::data::ConstElementPtr config, std::string& error) {
     ElementPtr errors(Element::createList());
     if (!checkConfig(config, errors)) {
-        error = std::string("Configuration error: " + errors->str());
+        error = "Configuration error: " + errors->str();
         return (NULL);
     }
     std::string dbfile = config->get(CONFIG_ITEM_DATABASE_FILE)->stringValue();
@@ -772,7 +772,7 @@ createInstance(isc::data::ConstElementPtr config, std::string& error) {
             new SQLite3Accessor(dbfile, isc::dns::RRClass::IN()));
         return (new DatabaseClient(isc::dns::RRClass::IN(), sqlite3_accessor));
     } catch (const std::exception& exc) {
-        error = exc.what();
+        error = std::string("Error creating sqlite3 datasource: ") + exc.what();
         return (NULL);
     }
 }

+ 6 - 0
src/lib/datasrc/sqlite3_accessor.h

@@ -200,6 +200,12 @@ private:
 ///
 /// This configuration setup is currently under discussion and will change in
 /// the near future.
+///
+/// \param config The configuration for the datasource instance
+/// \param error This string will be set to an error message if an error occurs
+///              during initialization
+/// \return An instance of the sqlite3 datasource client, or NULL if there was
+///         an error
 extern "C" DataSourceClient* createInstance(isc::data::ConstElementPtr config,
                                             std::string& error);
 

+ 0 - 5
src/lib/python/isc/datasrc/datasrc.cc

@@ -163,7 +163,6 @@ initModulePart_ZoneUpdater(PyObject* mod) {
 
 
 PyObject* po_DataSourceError;
-PyObject* po_DataSourceConfigError;
 PyObject* po_NotImplemented;
 
 PyModuleDef iscDataSrc = {
@@ -213,10 +212,6 @@ PyInit_datasrc(void) {
         po_DataSourceError = PyErr_NewException("isc.datasrc.Error", NULL,
                                                 NULL);
         PyObjectContainer(po_DataSourceError).installToModule(mod, "Error");
-        po_DataSourceConfigError = PyErr_NewException("isc.datasrc.ConfigError",
-                                                      NULL, NULL);
-        PyObjectContainer(po_DataSourceConfigError).installToModule(mod,
-                                                                "ConfigError");
         po_NotImplemented = PyErr_NewException("isc.datasrc.NotImplemented",
                                                NULL, NULL);
         PyObjectContainer(po_NotImplemented).installToModule(mod,