]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#115,!48] exception throwing replaced with gentler error logs 115-config-get-db-options 254-empty-class-update-fix
authorTomek Mrugalski <tomasz@isc.org>
Wed, 7 Nov 2018 19:58:25 +0000 (02:58 +0700)
committerTomek Mrugalski <tomasz@isc.org>
Wed, 7 Nov 2018 19:58:25 +0000 (02:58 +0700)
src/lib/database/database_connection.cc
src/lib/database/database_log.h
src/lib/database/db_messages.mes
src/lib/database/tests/database_connection_unittest.cc

index c5f183973877b0b67a2ad9c127325a806d7acd01..131266c5da4ff994203f680068ac3eb31859c0f5 100644 (file)
@@ -10,6 +10,7 @@
 #include <database/database_connection.h>
 #include <database/db_exceptions.h>
 #include <database/db_log.h>
+#include <database/db_messages.h>
 #include <exceptions/exceptions.h>
 
 #include <boost/algorithm/string.hpp>
@@ -174,8 +175,8 @@ DatabaseConnection::toElement(const ParameterMap& params) {
                 int_value = boost::lexical_cast<int64_t>(value);
                 result->set(keyword, isc::data::Element::create(int_value));
             } catch (...) {
-                isc_throw(ToElementError, "invalid DB access "
-                          << "integer parameter: " << keyword << "=" << value);
+                LOG_ERROR(database_logger, DATABASE_TO_JSON_ERROR)
+                    .arg("integer").arg(keyword).arg(value);
             }
         } else if ((keyword == "persist") ||
                    (keyword == "readonly") ||
@@ -186,8 +187,8 @@ DatabaseConnection::toElement(const ParameterMap& params) {
             } else if (value == "false") {
                 result->set(keyword, isc::data::Element::create(false));
             } else {
-                isc_throw(ToElementError, "invalid DB access "
-                          << "boolean parameter: " << keyword << "=" << value);
+                LOG_ERROR(database_logger, DATABASE_TO_JSON_ERROR)
+                    .arg("boolean").arg(keyword).arg(value);
             }
         } else if ((keyword == "type") ||
                    (keyword == "user") ||
@@ -198,8 +199,8 @@ DatabaseConnection::toElement(const ParameterMap& params) {
                    (keyword == "keyspace")) {
             result->set(keyword, isc::data::Element::create(value));
         } else {
-            isc_throw(ToElementError, "unknown DB access parameter: "
-                      << keyword << "=" << value);
+            LOG_ERROR(database_logger, DATABASE_TO_JSON_ERROR)
+                    .arg("unknown").arg(keyword).arg(value);
         }
     }
 
index 33b1e757a396e2d6b49fe6e7ab506bd847e37099..f42c85ca898366d542fa277d6b01b9201afe714f 100644 (file)
@@ -7,6 +7,9 @@
 #ifndef DATABASE_LOG_H
 #define DATABASE_LOG_H
 
+#include <databaae/db_messages.h>
+#include <log/macros.h>
+
 namespace isc {
 namespace db {
 
index 9d26a06e0334b5f9a3a7b21bd011e324b510b41c..c6206532c29df1ab2d03400f7c6c8dc1579f6b64 100644 (file)
@@ -84,3 +84,9 @@ transactions in this case. This message is issued when data is
 inserted into multiple tables with multiple INSERT statements
 and there may be a need to rollback the whole transaction if
 any of these INSERT statements fail.
+
+% DATABASE_TO_JSON_ERROR Internal logic error: uknown %1 element found in state: %2
+This error message is printed when conversion to JSON of the internal state is requested,
+but the connection string contains unrecognized parameter. This is a programming error.
+The software will continue operation, but the returned JSON data will be syntactically
+valid, but incomplete. The unknown parameter will not be converted.
index 508c120e4de0fbab51dec9dd513d338534088554..4e562d0d9cc28bf11f6f539f99c34eb5e11625af 100644 (file)
@@ -294,7 +294,13 @@ TEST(DatabaseConnection, toElementDbAccessStringValid) {
 // Check that toElementDbAccessString() catches invalid parameters.
 // Note that because toElementDbAccessString() utilizes
 // toElement() this tests both.
-TEST(DatabaseConnection, toElementDbAccessStringInvalid) {
+//
+// Test has been disabled. The recent change turned handling of unknown connection
+// string params. Instead of throwing, it logs an error and continues. This gives
+// us better resiliency. However, we don't have any means implemented to
+// test whether it was printed or not. It's reasonably easy to implement such a
+// check, but we don't have time for this.
+TEST(DatabaseConnection, DISABLED_toElementDbAccessStringInvalid) {
     std::vector<std::string> access_strs = {
         "bogus-param=memfile",
         "lfc-interval=not-an-integer",
@@ -305,10 +311,8 @@ TEST(DatabaseConnection, toElementDbAccessStringInvalid) {
     };
 
     for (auto access_str : access_strs) {
-        ASSERT_THROW(DatabaseConnection::toElementDbAccessString(access_str),
-                     isc::ToElementError)
-                    << "access string should have failed, string=["
-                    << access_str << "]";
+        /// @todo: verify that an ERROR is logged.
+        ASSERT_NO_THROW(DatabaseConnection::toElementDbAccessString(access_str));
     }
 }