BIND 10 master, updated. 3a9c1b6387eb19a1749e7e9a4dec753b33da5766 [master] Add explicit exception what strings

BIND 10 source code commits bind10-changes at lists.isc.org
Thu May 3 15:34:05 UTC 2012


The branch, master has been updated
       via  3a9c1b6387eb19a1749e7e9a4dec753b33da5766 (commit)
      from  7b0e7e17467d2a8c31fd8a8b4ab34e16f1ad84bf (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 3a9c1b6387eb19a1749e7e9a4dec753b33da5766
Author: Jelte Jansen <jelte at isc.org>
Date:   Thu May 3 17:32:31 2012 +0200

    [master] Add explicit exception what strings
    
    This should fix the unit tests complaining about wrong error messages.
    
    While debugging, I also found an uninitialized value error that has been present probably since the logger code exists. This has also been fixed.

-----------------------------------------------------------------------

Summary of changes:
 src/lib/exceptions/exceptions.h |   22 +++++++++++++++++++
 src/lib/log/compiler/message.cc |   20 ++++++++++-------
 src/lib/log/message_exception.h |   21 +++++++++--------
 src/lib/log/message_reader.cc   |   45 ++++++++++++++++++++++----------------
 src/lib/log/message_reader.h    |    2 +-
 5 files changed, 72 insertions(+), 38 deletions(-)

-----------------------------------------------------------------------
diff --git a/src/lib/exceptions/exceptions.h b/src/lib/exceptions/exceptions.h
index 562cc49..010fd39 100644
--- a/src/lib/exceptions/exceptions.h
+++ b/src/lib/exceptions/exceptions.h
@@ -207,6 +207,28 @@ public:
         throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2); \
     } while (1)
 
+///
+/// Similar as isc_throw, but allows the exception to have three additional
+/// parameters (the stream/text goes first)
+#define isc_throw_3(type, stream, param1, param2, param3) \
+    do { \
+        std::ostringstream oss__; \
+        oss__ << stream; \
+        throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2,\
+                   param3); \
+    } while (1)
+
+///
+/// Similar as isc_throw, but allows the exception to have four additional
+/// parameters (the stream/text goes first)
+#define isc_throw_4(type, stream, param1, param2, param3, param4) \
+    do { \
+        std::ostringstream oss__; \
+        oss__ << stream; \
+        throw type(__FILE__, __LINE__, oss__.str().c_str(), param1, param2,\
+                   param3, param4); \
+    } while (1)
+
 }
 #endif // __EXCEPTIONS_H
 
diff --git a/src/lib/log/compiler/message.cc b/src/lib/log/compiler/message.cc
index bb10481..1e71b41 100644
--- a/src/lib/log/compiler/message.cc
+++ b/src/lib/log/compiler/message.cc
@@ -327,8 +327,9 @@ writeHeaderFile(const string& file, const vector<string>& ns_components,
     ofstream hfile(header_file.fullName().c_str());
 
     if (hfile.fail()) {
-        isc_throw_2(MessageException, LOG_OPEN_OUTPUT_FAIL,
-                    header_file.fullName(), strerror(errno));
+        isc_throw_4(MessageException, "Failed to open output file",
+                    LOG_OPEN_OUTPUT_FAIL, header_file.fullName(),
+                    strerror(errno), 0);
     }
 
     // Write the header preamble.  If there is an error, we'll pick it up
@@ -361,8 +362,9 @@ writeHeaderFile(const string& file, const vector<string>& ns_components,
 
     // Report errors (if any) and exit
     if (hfile.fail()) {
-        isc_throw_2(MessageException, LOG_WRITE_ERROR, header_file.fullName(),
-                    strerror(errno));
+        isc_throw_4(MessageException, "Error writing to output file",
+                    LOG_WRITE_ERROR, header_file.fullName(), strerror(errno),
+                    0);
     }
 
     hfile.close();
@@ -427,8 +429,9 @@ writeProgramFile(const string& file, const vector<string>& ns_components,
     ofstream ccfile(program_file.fullName().c_str());
 
     if (ccfile.fail()) {
-        isc_throw_2(MessageException, LOG_OPEN_OUTPUT_FAIL,
-                    program_file.fullName(), strerror(errno));
+        isc_throw_4(MessageException, "Error opening output file",
+                    LOG_OPEN_OUTPUT_FAIL, program_file.fullName(),
+                    strerror(errno), 0);
     }
 
     // Write the preamble.  If there is an error, we'll pick it up after
@@ -485,8 +488,9 @@ writeProgramFile(const string& file, const vector<string>& ns_components,
 
     // Report errors (if any) and exit
     if (ccfile.fail()) {
-        isc_throw_2(MessageException, LOG_WRITE_ERROR, program_file.fullName(),
-                    strerror(errno));
+        isc_throw_4(MessageException, "Error writing to output file",
+                    LOG_WRITE_ERROR, program_file.fullName(), strerror(errno),
+                    0);
     }
 
     ccfile.close();
diff --git a/src/lib/log/message_exception.h b/src/lib/log/message_exception.h
index bc4c3d8..cd6caf2 100644
--- a/src/lib/log/message_exception.h
+++ b/src/lib/log/message_exception.h
@@ -40,11 +40,11 @@ public:
     ///
     /// \param id Message identification.
     /// \param lineno Line number on which error occurred (if > 0).
-    MessageException(const char* file, size_t line,
-                     MessageID id, int lineno = 0)
-        : isc::Exception(file, line, ""), id_(id)
+    MessageException(const char* file, size_t line, const char* what,
+                     MessageID id, int lineno)
+        : isc::Exception(file, line, what), id_(id), lineno_(lineno)
     {
-        if (lineno > 0) {
+        if (lineno_ > 0) {
             args_.push_back(boost::lexical_cast<std::string>(lineno));
         }
     }
@@ -54,9 +54,9 @@ public:
     /// \param id Message identification.
     /// \param arg1 First message argument.
     /// \param lineno Line number on which error occurred (if > 0).
-    MessageException(const char* file, size_t line,
-                     MessageID id, const std::string& arg1, int lineno = 0)
-        : isc::Exception(file, line, ""), id_(id)
+    MessageException(const char* file, size_t line, const char* what,
+                     MessageID id, const std::string& arg1, int lineno)
+        : isc::Exception(file, line, what), id_(id)
     {
         if (lineno > 0) {
             args_.push_back(boost::lexical_cast<std::string>(lineno));
@@ -70,10 +70,10 @@ public:
     /// \param arg1 First message argument.
     /// \param arg2 Second message argument.
     /// \param lineno Line number on which error occurred (if > 0).
-    MessageException(const char* file, size_t line,
+    MessageException(const char* file, size_t line, const char *what,
                      MessageID id, const std::string& arg1,
-                     const std::string& arg2, int lineno = 0)
-        : isc::Exception(file, line, ""), id_(id)
+                     const std::string& arg2, int lineno)
+        : isc::Exception(file, line, what), id_(id)
     {
         if (lineno > 0) {
             args_.push_back(boost::lexical_cast<std::string>(lineno));
@@ -102,6 +102,7 @@ public:
 private:
     MessageID                   id_;        // Exception ID
     std::vector<std::string>    args_;      // Exception arguments
+    int lineno_;
 };
 
 } // namespace log
diff --git a/src/lib/log/message_reader.cc b/src/lib/log/message_reader.cc
index 700d5c6..b5a4d35 100644
--- a/src/lib/log/message_reader.cc
+++ b/src/lib/log/message_reader.cc
@@ -48,8 +48,8 @@ MessageReader::readFile(const string& file, MessageReader::Mode mode) {
     // Open the file.
     ifstream infile(file.c_str());
     if (infile.fail()) {
-        isc_throw_2(MessageException, LOG_INPUT_OPEN_FAIL, file,
-                    strerror(errno));
+        isc_throw_4(MessageException, "Failed to open message file",
+                    LOG_INPUT_OPEN_FAIL, file, strerror(errno), 0);
     }
 
     // Loop round reading it.  As we process the file one line at a time,
@@ -66,7 +66,8 @@ MessageReader::readFile(const string& file, MessageReader::Mode mode) {
 
     // Why did the loop terminate?
     if (!infile.eof()) {
-        isc_throw_2(MessageException, LOG_READ_ERROR, file, strerror(errno));
+        isc_throw_4(MessageException, "Error reading message file",
+                    LOG_READ_ERROR, file, strerror(errno), 0);
     }
     infile.close();
 }
@@ -115,7 +116,8 @@ MessageReader::parseDirective(const std::string& text) {
     } else {
 
         // Unrecognised directive
-        isc_throw_2(MessageException, LOG_UNRECOGNISED_DIRECTIVE, tokens[0],
+        isc_throw_3(MessageException, "Unrecognized directive",
+                    LOG_UNRECOGNISED_DIRECTIVE, tokens[0],
                     lineno_);
     }
 }
@@ -140,14 +142,15 @@ MessageReader::parsePrefix(const vector<string>& tokens) {
         // and numeric characters (and underscores) and does not start with a
         // digit.
         if (invalidSymbol(prefix_)) {
-            isc_throw_2(MessageException, LOG_PREFIX_INVALID_ARG, prefix_,
-                        lineno_);
+            isc_throw_3(MessageException, "Invalid prefix",
+                        LOG_PREFIX_INVALID_ARG, prefix_, lineno_);
         }
 
     } else {
 
         // Too many arguments
-        isc_throw_1(MessageException, LOG_PREFIX_EXTRA_ARGS, lineno_);
+        isc_throw_2(MessageException, "Too many arguments",
+                    LOG_PREFIX_EXTRA_ARGS, lineno_);
     }
 }
 
@@ -175,10 +178,12 @@ MessageReader::parseNamespace(const vector<string>& tokens) {
 
     // Check argument count
     if (tokens.size() < 2) {
-        isc_throw_1(MessageException, LOG_NAMESPACE_NO_ARGS, lineno_);
+        isc_throw_2(MessageException, "No arguments", LOG_NAMESPACE_NO_ARGS,
+                    lineno_);
 
     } else if (tokens.size() > 2) {
-        isc_throw_1(MessageException, LOG_NAMESPACE_EXTRA_ARGS, lineno_);
+        isc_throw_2(MessageException, "Too many arguments",
+                    LOG_NAMESPACE_EXTRA_ARGS, lineno_);
 
     }
 
@@ -190,13 +195,14 @@ MessageReader::parseNamespace(const vector<string>& tokens) {
                                       "abcdefghijklmnopqrstuvwxyz"
                                       "0123456789_:";
     if (tokens[1].find_first_not_of(valid_chars) != string::npos) {
-        isc_throw_2(MessageException, LOG_NAMESPACE_INVALID_ARG, tokens[1],
-                    lineno_);
+        isc_throw_3(MessageException, "Invalid argument",
+                    LOG_NAMESPACE_INVALID_ARG, tokens[1], lineno_);
     }
 
     // All OK - unless the namespace has already been set.
     if (ns_.size() != 0) {
-        isc_throw_1(MessageException, LOG_DUPLICATE_NAMESPACE, lineno_);
+        isc_throw_2(MessageException, "Duplicate namespace",
+                    LOG_DUPLICATE_NAMESPACE, lineno_);
     }
 
     // Prefix has not been set, so set it and return success.
@@ -223,7 +229,8 @@ MessageReader::parseMessage(const std::string& text, MessageReader::Mode mode) {
 
     // A line comprising just the message introducer is not valid.
     if (text.size() == 1) {
-        isc_throw_2(MessageException, LOG_NO_MESSAGE_ID, text, lineno_);
+        isc_throw_3(MessageException, "No message ID", LOG_NO_MESSAGE_ID,
+                    text, lineno_);
     }
 
     // Strip off the introducer and any leading space after that.
@@ -234,8 +241,8 @@ MessageReader::parseMessage(const std::string& text, MessageReader::Mode mode) {
     if (first_delim == string::npos) {
 
         // Just a single token in the line - this is not valid
-        isc_throw_2(MessageException, LOG_NO_MESSAGE_TEXT, message_line,
-                    lineno_);
+        isc_throw_3(MessageException, "No message text", LOG_NO_MESSAGE_TEXT,
+                    message_line, lineno_);
     }
 
     // Extract the first token into the message ID, preceding it with the
@@ -245,8 +252,8 @@ MessageReader::parseMessage(const std::string& text, MessageReader::Mode mode) {
     string ident = prefix_ + message_line.substr(0, first_delim);
     if (prefix_.empty()) {
         if (invalidSymbol(ident)) {
-            isc_throw_2(MessageException, LOG_INVALID_MESSAGE_ID, ident,
-                        lineno_);
+            isc_throw_3(MessageException, "Invalid message ID",
+                        LOG_INVALID_MESSAGE_ID, ident, lineno_);
         }
     }
     isc::util::str::uppercase(ident);
@@ -258,8 +265,8 @@ MessageReader::parseMessage(const std::string& text, MessageReader::Mode mode) {
         // ?? This happens if there are trailing delimiters, which should not
         // occur as we have stripped trailing spaces off the line.  Just treat
         // this as a single-token error for simplicity's sake.
-        isc_throw_2(MessageException, LOG_NO_MESSAGE_TEXT, message_line,
-                    lineno_);
+        isc_throw_3(MessageException, "No message text", LOG_NO_MESSAGE_TEXT,
+                    message_line, lineno_);
     }
 
     // Add the result to the dictionary and to the non-added list if the add to
diff --git a/src/lib/log/message_reader.h b/src/lib/log/message_reader.h
index eded9c6..a468d43 100644
--- a/src/lib/log/message_reader.h
+++ b/src/lib/log/message_reader.h
@@ -61,7 +61,7 @@ public:
     /// The ownership of the dictionary object is not transferred - the caller
     /// is responsible for managing the lifetime of the dictionary.
     MessageReader(MessageDictionary* dictionary = NULL) :
-        dictionary_(dictionary)
+        dictionary_(dictionary), lineno_(0)
     {}
 
     /// \brief Virtual Destructor



More information about the bind10-changes mailing list