Browse Source

[2518] Introduce DNSTextError and remove generic catch for isc::Exception from the MasterLoader

Mukund Sivaraman 11 years ago
parent
commit
ab8ff1eda4

+ 11 - 2
src/lib/dns/exceptions.h

@@ -37,12 +37,21 @@ public:
 };
 
 ///
+/// \brief Base class for all sorts of text parse errors.
+///
+class DNSTextError : public isc::dns::Exception {
+public:
+    DNSTextError(const char* file, size_t line, const char* what) :
+        isc::dns::Exception(file, line, what) {}
+};
+
+///
 /// \brief Base class for name parser exceptions.
 ///
-class NameParserException : public isc::dns::Exception {
+class NameParserException : public DNSTextError {
 public:
     NameParserException(const char* file, size_t line, const char* what) :
-        isc::dns::Exception(file, line, what) {}
+        DNSTextError(file, line, what) {}
 };
 
 class DNSProtocolError : public isc::dns::Exception {

+ 13 - 9
src/lib/dns/master_loader.cc

@@ -576,15 +576,19 @@ MasterLoader::MasterLoaderImpl::loadIncremental(size_t count_limit) {
                     isc_throw(MasterLoaderError, "Invalid RR data");
                 }
             }
-        } catch (const MasterLoaderError&) {
-            // This is a hack. We exclude the MasterLoaderError from the
-            // below case. Once we restrict the below to some smaller
-            // exception, we should remove this.
-            throw;
-        } catch (const isc::Exception& e) {
-            // TODO: Once we do #2518, catch only the DNSTextError here,
-            // not isc::Exception. The rest should be just simply
-            // propagated.
+        } catch (const isc::dns::DNSTextError& e) {
+            reportError(lexer_.getSourceName(), lexer_.getSourceLine(),
+                        e.what());
+            eatUntilEOL(false);
+        } catch (const MasterLexer::ReadError& e) {
+            reportError(lexer_.getSourceName(), lexer_.getSourceLine(),
+                        e.what());
+            eatUntilEOL(false);
+        } catch (const MasterLexer::LexerError& e) {
+            reportError(lexer_.getSourceName(), lexer_.getSourceLine(),
+                        e.what());
+            eatUntilEOL(false);
+        } catch (const InternalException& e) {
             reportError(lexer_.getSourceName(), lexer_.getSourceLine(),
                         e.what());
             eatUntilEOL(false);

+ 6 - 6
src/lib/dns/rdata.h

@@ -42,20 +42,20 @@ namespace rdata {
 /// \brief A standard DNS module exception that is thrown if RDATA parser
 /// encounters an invalid or inconsistent data length.
 ///
-class InvalidRdataLength : public isc::dns::Exception {
+class InvalidRdataLength : public DNSTextError {
 public:
     InvalidRdataLength(const char* file, size_t line, const char* what) :
-        isc::dns::Exception(file, line, what) {}
+        DNSTextError(file, line, what) {}
 };
 
 ///
 /// \brief A standard DNS module exception that is thrown if RDATA parser
 /// fails to recognize a given textual representation.
 ///
-class InvalidRdataText : public isc::dns::Exception {
+class InvalidRdataText : public DNSTextError {
 public:
     InvalidRdataText(const char* file, size_t line, const char* what) :
-        isc::dns::Exception(file, line, what) {}
+        DNSTextError(file, line, what) {}
 };
 
 ///
@@ -63,10 +63,10 @@ public:
 /// encounters a character-string (as defined in RFC1035) exceeding
 /// the maximum allowable length (\c MAX_CHARSTRING_LEN).
 ///
-class CharStringTooLong : public isc::dns::Exception {
+class CharStringTooLong : public DNSTextError {
 public:
     CharStringTooLong(const char* file, size_t line, const char* what) :
-        isc::dns::Exception(file, line, what) {}
+        DNSTextError(file, line, what) {}
 };
 
 // Forward declaration to define RdataPtr.

+ 2 - 2
src/lib/dns/rrclass-placeholder.h

@@ -39,10 +39,10 @@ class AbstractMessageRenderer;
 /// \brief A standard DNS module exception that is thrown if an RRClass object
 /// is being constructed from an unrecognized string.
 ///
-class InvalidRRClass : public isc::dns::Exception {
+class InvalidRRClass : public DNSTextError {
 public:
     InvalidRRClass(const char* file, size_t line, const char* what) :
-        isc::dns::Exception(file, line, what) {}
+        DNSTextError(file, line, what) {}
 };
 
 ///

+ 2 - 2
src/lib/dns/rrttl.h

@@ -36,10 +36,10 @@ class AbstractMessageRenderer;
 /// \brief A standard DNS module exception that is thrown if an RRTTL object
 /// is being constructed from an unrecognized string.
 ///
-class InvalidRRTTL : public isc::dns::Exception {
+class InvalidRRTTL : public DNSTextError {
 public:
     InvalidRRTTL(const char* file, size_t line, const char* what) :
-        isc::dns::Exception(file, line, what) {}
+        DNSTextError(file, line, what) {}
 };
 
 ///

+ 2 - 2
src/lib/dns/rrtype-placeholder.h

@@ -42,10 +42,10 @@ class AbstractMessageRenderer;
 /// \brief A standard DNS module exception that is thrown if an RRType object
 /// is being constructed from an unrecognized string.
 ///
-class InvalidRRType : public isc::dns::Exception {
+class InvalidRRType : public DNSTextError {
 public:
     InvalidRRType(const char* file, size_t line, const char* what) :
-        isc::dns::Exception(file, line, what) {}
+        DNSTextError(file, line, what) {}
 };
 
 ///