]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[1964] use assert() instead of throwing exception in checkExcessPlaceholders.
authorJINMEI Tatuya <jinmei@isc.org>
Tue, 8 May 2012 22:57:11 +0000 (15:57 -0700)
committerJINMEI Tatuya <jinmei@isc.org>
Tue, 8 May 2012 22:57:11 +0000 (15:57 -0700)
unfortunatelly, we cannot throw here because it's called from the Formatter
destructor.  death tests now work for environments where it previously failed.

src/lib/log/log_formatter.cc
src/lib/log/tests/log_formatter_unittest.cc

index c9ecdd3b3f748f1ca8822432d62213592d61b29c..c728cb5dd31625a23d15a14702e35aa79b9f3b5a 100644 (file)
@@ -15,6 +15,8 @@
 #include "config.h"
 #include <log/log_formatter.h>
 
+#include <cassert>
+
 using namespace std;
 using namespace boost;
 
@@ -52,11 +54,12 @@ checkExcessPlaceholders(string* message, unsigned int placeholder) {
     const string mark("%" + lexical_cast<string>(placeholder));
     const size_t pos(message->find(mark));
     if (pos != string::npos) {
+        // Excess placeholders were found.  If we enable the harsh check,
+        // abort it.  Note: ideally we'd like to throw MismatchedPlaceholders,
+        // but we can't at least for now because this function is called from
+        // the Formatter's destructor.
 #ifdef ENABLE_LOGGER_CHECKS
-        // Excess placeholders were found, so throw an exception
-        isc_throw(MismatchedPlaceholders,
-                 "Excess logger placeholders still exist in message: "
-                  << *message);
+        assert("Excess logger placeholders still exist in message" == NULL);
 #else
         message->append(" @@Excess logger placeholders still exist@@");
 #endif /* ENABLE_LOGGER_CHECKS */
index 6bb2f02c7eff0c242e4a00f329e9701a6b7fcc25..e67a5081d5b23db5fbd23a680722726cb540455c 100644 (file)
@@ -106,12 +106,14 @@ TEST_F(FormatterTest, multiArg) {
 TEST_F(FormatterTest, mismatchedPlaceholders) {
     EXPECT_DEATH({
         isc::util::unittests::dontCreateCoreDumps();
-        Formatter(isc::log::INFO, s("Missing the first %2"), this).arg("missing").arg("argument");
+        Formatter(isc::log::INFO, s("Missing the first %2"), this).
+            arg("missing").arg("argument");
     }, ".*");
 
     EXPECT_DEATH({
         isc::util::unittests::dontCreateCoreDumps();
-        Formatter(isc::log::INFO, s("Too many arguments in %1 %2"), this).arg("only one");
+        Formatter(isc::log::INFO, s("Too many arguments in %1 %2"), this).
+            arg("only one");
     }, ".*");
 }
 #endif /* EXPECT_DEATH */