BIND 10 trac2421, updated. bc457a13e13b10079985213922c579634e20ca11 [2421] Throw ZoneLoaderException even for MasterLoadError

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Nov 14 08:16:16 UTC 2012


The branch, trac2421 has been updated
       via  bc457a13e13b10079985213922c579634e20ca11 (commit)
       via  0d08fcb9a4218410fa08bbb7b70802de5af04525 (commit)
       via  5ba2cab585357a99f0bfadeb8f8488150e40f923 (commit)
       via  9e1942f5eab1a46932990fe9dd85a8c02ac40a11 (commit)
       via  6c30834cb78baa51e6776452069ceda87d34864c (commit)
      from  cec4bf4314a6c8deaeadf10c5d95bc812480653a (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 bc457a13e13b10079985213922c579634e20ca11
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Nov 14 13:25:29 2012 +0530

    [2421] Throw ZoneLoaderException even for MasterLoadError

commit 0d08fcb9a4218410fa08bbb7b70802de5af04525
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Nov 14 13:18:26 2012 +0530

    [2421] Catch ZoneValidationException at a higher level
    
    Also split the iterator vs. file log message ids, so that they
    are used only in one place each.

commit 5ba2cab585357a99f0bfadeb8f8488150e40f923
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Nov 14 13:04:55 2012 +0530

    [2421] Update InMemoryClient doc about exceptions

commit 9e1942f5eab1a46932990fe9dd85a8c02ac40a11
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Nov 14 13:04:30 2012 +0530

    [2421] Throw AddError instead of OutOfZone when loading out-of-zone data
    
    OutOfZone is used in the ZoneFinder for other class of errors
    and we can't really bring it into the ZoneValidationException
    hierarchy.

commit 6c30834cb78baa51e6776452069ceda87d34864c
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Nov 14 12:19:43 2012 +0530

    [2421] Add zone exceptions hierarchy

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

Summary of changes:
 src/lib/datasrc/Makefile.am                        |    1 +
 src/lib/datasrc/client_list.cc                     |   27 +++------------
 src/lib/datasrc/datasrc_messages.mes               |   28 +++++-----------
 .../exceptions.h}                                  |   35 +++++++++++---------
 src/lib/datasrc/memory/memory_client.h             |    8 ++---
 src/lib/datasrc/memory/zone_data_loader.cc         |    6 +++-
 src/lib/datasrc/memory/zone_data_loader.h          |    5 +--
 src/lib/datasrc/memory/zone_data_updater.cc        |    2 +-
 src/lib/datasrc/memory/zone_data_updater.h         |   10 ++----
 .../datasrc/tests/memory/memory_client_unittest.cc |   10 +++---
 src/lib/datasrc/zone.h                             |    5 +--
 11 files changed, 58 insertions(+), 79 deletions(-)
 copy src/lib/{python/isc/datasrc/configurableclientlist_python.h => datasrc/exceptions.h} (54%)

-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/Makefile.am b/src/lib/datasrc/Makefile.am
index eccc147..f24d62c 100644
--- a/src/lib/datasrc/Makefile.am
+++ b/src/lib/datasrc/Makefile.am
@@ -26,6 +26,7 @@ lib_LTLIBRARIES = libb10-datasrc.la
 libb10_datasrc_la_SOURCES = data_source.h
 libb10_datasrc_la_SOURCES += rbnode_rrset.h
 libb10_datasrc_la_SOURCES += rbtree.h
+libb10_datasrc_la_SOURCES += exceptions.h
 libb10_datasrc_la_SOURCES += zonetable.h zonetable.cc
 libb10_datasrc_la_SOURCES += zone.h zone_finder.cc zone_finder_context.cc
 libb10_datasrc_la_SOURCES += result.h
diff --git a/src/lib/datasrc/client_list.cc b/src/lib/datasrc/client_list.cc
index 19ec3c3..397faae 100644
--- a/src/lib/datasrc/client_list.cc
+++ b/src/lib/datasrc/client_list.cc
@@ -14,6 +14,7 @@
 
 
 #include "client_list.h"
+#include "exceptions.h"
 #include "client.h"
 #include "factory.h"
 #include "memory/memory_client.h"
@@ -177,17 +178,8 @@ ConfigurableClientList::configure(const ConstElementPtr& config,
                         try {
                             cache->load(origin,
                                         paramConf->get(*it)->stringValue());
-                        } catch (const isc::dns::MasterLoadError& mle) {
-                            LOG_ERROR(logger, DATASRC_MASTERLOAD_ERROR)
-                                .arg(mle.what());
-                        } catch (const ZoneDataUpdater::NullRRset& e) {
-                            LOG_ERROR(logger, DATASRC_LOAD_NULL_RRSET_ERROR)
-                                .arg(e.what());
-                        } catch (const ZoneDataUpdater::AddError& e) {
-                            LOG_ERROR(logger, DATASRC_LOAD_ADD_ERROR)
-                                .arg(e.what());
-                        } catch (const isc::datasrc::memory::EmptyZone& e) {
-                            LOG_ERROR(logger, DATASRC_LOAD_EMPTY_ZONE_ERROR)
+                        } catch (const ZoneLoaderException& e) {
+                            LOG_ERROR(logger, DATASRC_LOAD_FROM_FILE_ERROR)
                                 .arg(e.what());
                         }
                     } else {
@@ -205,17 +197,8 @@ ConfigurableClientList::configure(const ConstElementPtr& config,
                         }
                         try {
                             cache->load(origin, *iterator);
-                        } catch (const isc::dns::MasterLoadError& mle) {
-                            LOG_ERROR(logger, DATASRC_MASTERLOAD_ERROR)
-                                .arg(mle.what());
-                        } catch (const ZoneDataUpdater::NullRRset& e) {
-                            LOG_ERROR(logger, DATASRC_LOAD_NULL_RRSET_ERROR)
-                                .arg(e.what());
-                        } catch (const ZoneDataUpdater::AddError& e) {
-                            LOG_ERROR(logger, DATASRC_LOAD_ADD_ERROR)
-                                .arg(e.what());
-                        } catch (const isc::datasrc::memory::EmptyZone& e) {
-                            LOG_ERROR(logger, DATASRC_LOAD_EMPTY_ZONE_ERROR)
+                        } catch (const ZoneLoaderException& e) {
+                            LOG_ERROR(logger, DATASRC_LOAD_FROM_ITERATOR_ERROR)
                                 .arg(e.what());
                         }
                     }
diff --git a/src/lib/datasrc/datasrc_messages.mes b/src/lib/datasrc/datasrc_messages.mes
index 3788a48..54b22ad 100644
--- a/src/lib/datasrc/datasrc_messages.mes
+++ b/src/lib/datasrc/datasrc_messages.mes
@@ -305,25 +305,15 @@ Therefore, the zone will not be available for this process. If this is
 a problem, you should move the zone to some database backend (sqlite3, for
 example) and use it from there.
 
-% DATASRC_MASTERLOAD_ERROR %1
-An error was found in the zone data for a MasterFiles zone. The zone
-is not loaded. The specific error is shown in the message, and should
-be addressed.
-
-% DATASRC_LOAD_ADD_ERROR %1
-An error was found in the zone data when it was being loaded. The zone
-was not loaded. The specific error is shown in the message, and should
-be addressed.
-
-% DATASRC_LOAD_NULL_RRSET_ERROR %1
-A NULL RRset was passed to be added to a zone. The zone was not
-loaded. The specific error is shown in the message, and should be
-addressed.
-
-% DATASRC_LOAD_EMPTY_ZONE_ERROR %1
-A zone was asked to be loaded without any zone data. The zone was not
-loaded. The specific error is shown in the message, and should be
-addressed.
+% DATASRC_LOAD_FROM_FILE_ERROR %1
+An error was found in the zone data when it was being loaded from a
+file. The zone was not loaded. The specific error is shown in the
+message, and should be addressed.
+
+% DATASRC_LOAD_FROM_ITERATOR_ERROR %1
+An error was found in the zone data when it was being loaded from an
+iterator. The zone was not loaded. The specific error is shown in the
+message, and should be addressed.
 
 % DATASRC_MEM_ADD_RRSET adding RRset '%1/%2' into zone '%3'
 Debug information. An RRset is being added to the in-memory data source.
diff --git a/src/lib/datasrc/exceptions.h b/src/lib/datasrc/exceptions.h
new file mode 100644
index 0000000..749b955
--- /dev/null
+++ b/src/lib/datasrc/exceptions.h
@@ -0,0 +1,47 @@
+// Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+//
+// Permission to use, copy, modify, and/or distribute this software for any
+// purpose with or without fee is hereby granted, provided that the above
+// copyright notice and this permission notice appear in all copies.
+//
+// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
+// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+// AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
+// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+// PERFORMANCE OF THIS SOFTWARE.
+
+#ifndef DATASRC_EXCEPTIONS_H
+#define DATASRC_EXCEPTIONS_H 1
+
+#include <exceptions/exceptions.h>
+
+namespace isc {
+namespace datasrc {
+
+/// Base class for a number of exceptions that are thrown while working
+/// with zones.
+struct ZoneException : public Exception {
+    ZoneException(const char* file, size_t line, const char* what) :
+        Exception(file, line, what)
+    {}
+};
+
+/// Base class for a number of exceptions that are thrown when zones are
+/// being loaded. This is a recoverable exception. It should be possible
+/// to skip the bad zone and continue loading/serving other zones.
+struct ZoneLoaderException : public ZoneException {
+    ZoneLoaderException(const char* file, size_t line, const char* what) :
+        ZoneException(file, line, what)
+    {}
+};
+
+} // namespace datasrc
+} // namespace isc
+
+#endif // DATASRC_EXCEPTIONS
+
+// Local Variables:
+// mode: c++
+// End:
diff --git a/src/lib/datasrc/memory/memory_client.h b/src/lib/datasrc/memory/memory_client.h
index 3218c75..169421f 100644
--- a/src/lib/datasrc/memory/memory_client.h
+++ b/src/lib/datasrc/memory/memory_client.h
@@ -87,11 +87,11 @@ public:
     /// current content. The masterfile parsing ability is kind of limited,
     /// see isc::dns::masterLoad.
     ///
-    /// This throws isc::dns::MasterLoadError if there is problem with loading
-    /// (missing file, malformed, it contains different zone, etc - see
-    /// isc::dns::masterLoad for details).
+    /// This throws isc::dns::MasterLoadError or AddError if there are
+    /// problems with loading (missing file, malformed data, unexpected
+    /// zone, etc. - see isc::dns::masterLoad for details).
     ///
-    /// In case of internal problems, OutOfZone, NullRRset or AssertError could
+    /// In case of internal problems, NullRRset or AssertError could
     /// be thrown, but they should not be expected. Exceptions caused by
     /// allocation may be thrown as well.
     ///
diff --git a/src/lib/datasrc/memory/zone_data_loader.cc b/src/lib/datasrc/memory/zone_data_loader.cc
index d759901..d0a43a3 100644
--- a/src/lib/datasrc/memory/zone_data_loader.cc
+++ b/src/lib/datasrc/memory/zone_data_loader.cc
@@ -207,7 +207,11 @@ void
 masterLoadWrapper(const char* const filename, const Name& origin,
                   const RRClass& zone_class, LoadCallback callback)
 {
-    masterLoad(filename, origin, zone_class, boost::bind(callback, _1));
+    try {
+        masterLoad(filename, origin, zone_class, boost::bind(callback, _1));
+    } catch (MasterLoadError& e) {
+        isc_throw(ZoneLoaderException, e.what());
+    }
 }
 
 // The installer called from the iterator version of loadZoneData().
diff --git a/src/lib/datasrc/memory/zone_data_loader.h b/src/lib/datasrc/memory/zone_data_loader.h
index 6f02fcb..6b409ec 100644
--- a/src/lib/datasrc/memory/zone_data_loader.h
+++ b/src/lib/datasrc/memory/zone_data_loader.h
@@ -15,6 +15,7 @@
 #ifndef DATASRC_ZONE_DATA_LOADER_H
 #define DATASRC_ZONE_DATA_LOADER_H 1
 
+#include <datasrc/exceptions.h>
 #include <datasrc/memory/zone_data.h>
 #include <datasrc/iterator.h>
 #include <dns/name.h>
@@ -29,9 +30,9 @@ namespace memory {
 ///
 /// This is thrown if an empty zone would be created during
 /// \c loadZoneData().
-struct EmptyZone : public InvalidParameter {
+struct EmptyZone : public ZoneLoaderException {
     EmptyZone(const char* file, size_t line, const char* what) :
-        InvalidParameter(file, line, what)
+        ZoneLoaderException(file, line, what)
     {}
 };
 
diff --git a/src/lib/datasrc/memory/zone_data_updater.cc b/src/lib/datasrc/memory/zone_data_updater.cc
index 037eeb4..3df8c66 100644
--- a/src/lib/datasrc/memory/zone_data_updater.cc
+++ b/src/lib/datasrc/memory/zone_data_updater.cc
@@ -158,7 +158,7 @@ ZoneDataUpdater::validate(const isc::dns::ConstRRsetPtr rrset) const {
         LOG_ERROR(logger,
                   DATASRC_MEMORY_MEM_OUT_OF_ZONE).arg(rrset->getName()).
             arg(zone_name_);
-        isc_throw(OutOfZone,
+        isc_throw(AddError,
                   "The name " << rrset->getName() <<
                   " is not contained in zone " << zone_name_);
     }
diff --git a/src/lib/datasrc/memory/zone_data_updater.h b/src/lib/datasrc/memory/zone_data_updater.h
index 341d8ae..fa9a6af 100644
--- a/src/lib/datasrc/memory/zone_data_updater.h
+++ b/src/lib/datasrc/memory/zone_data_updater.h
@@ -15,6 +15,7 @@
 #ifndef DATASRC_ZONE_DATA_UPDATER_H
 #define DATASRC_ZONE_DATA_UPDATER_H 1
 
+#include <datasrc/exceptions.h>
 #include <datasrc/memory/zone_data.h>
 #include <datasrc/memory/rdata_serialization.h>
 #include <dns/name.h>
@@ -94,14 +95,9 @@ public:
     ///
     /// This is thrown against general error cases in adding an RRset
     /// to the zone.
-    ///
-    /// Note: this exception would cover cases for \c OutOfZone or
-    /// \c NullRRset.  We'll need to clarify and unify the granularity
-    /// of exceptions eventually.  For now, exceptions are added as
-    /// developers see the need for it.
-    struct AddError : public InvalidParameter {
+    struct AddError : public ZoneLoaderException {
         AddError(const char* file, size_t line, const char* what) :
-            InvalidParameter(file, line, what)
+            ZoneLoaderException(file, line, what)
         {}
     };
 
diff --git a/src/lib/datasrc/tests/memory/memory_client_unittest.cc b/src/lib/datasrc/tests/memory/memory_client_unittest.cc
index c1d2f30..38f6eff 100644
--- a/src/lib/datasrc/tests/memory/memory_client_unittest.cc
+++ b/src/lib/datasrc/tests/memory/memory_client_unittest.cc
@@ -186,7 +186,7 @@ TEST_F(MemoryClientTest, loadRRsetDoesntMatchOrigin) {
     // in an exception.
     EXPECT_THROW(client_->load(Name("example.com"),
                                TEST_DATA_DIR "/example.org-empty.zone"),
-                 MasterLoadError);
+                 ZoneLoaderException);
 }
 
 TEST_F(MemoryClientTest, loadErrorsInParsingZoneMustNotLeak1) {
@@ -195,7 +195,7 @@ TEST_F(MemoryClientTest, loadErrorsInParsingZoneMustNotLeak1) {
     // allocations.
     EXPECT_THROW(client_->load(Name("example.org"),
                                TEST_DATA_DIR "/example.org-broken1.zone"),
-                 MasterLoadError);
+                 ZoneLoaderException);
     // Teardown checks for memory segment leaks
 }
 
@@ -205,14 +205,14 @@ TEST_F(MemoryClientTest, loadErrorsInParsingZoneMustNotLeak2) {
     // allocations.
     EXPECT_THROW(client_->load(Name("example.org"),
                                TEST_DATA_DIR "/example.org-broken2.zone"),
-                 MasterLoadError);
+                 ZoneLoaderException);
     // Teardown checks for memory segment leaks
 }
 
 TEST_F(MemoryClientTest, loadNonExistentZoneFile) {
     EXPECT_THROW(client_->load(Name("example.org"),
                                TEST_DATA_DIR "/somerandomfilename"),
-                 MasterLoadError);
+                 ZoneLoaderException);
     // Teardown checks for memory segment leaks
 }
 
@@ -478,7 +478,7 @@ TEST_F(MemoryClientTest, loadOutOfZoneThrows) {
     EXPECT_THROW(client_->load(Name("example.org"),
                                TEST_DATA_DIR
                                "/example.org-out-of-zone.zone"),
-                 MasterLoadError);
+                 ZoneLoaderException);
     // Teardown checks for memory segment leaks
 }
 
diff --git a/src/lib/datasrc/zone.h b/src/lib/datasrc/zone.h
index 9572ed0..0d7438d 100644
--- a/src/lib/datasrc/zone.h
+++ b/src/lib/datasrc/zone.h
@@ -19,6 +19,7 @@
 #include <dns/rrset.h>
 #include <dns/rrtype.h>
 
+#include <datasrc/exceptions.h>
 #include <datasrc/result.h>
 
 #include <utility>
@@ -31,10 +32,10 @@ namespace datasrc {
 ///
 /// This is thrown when a method is called for a name or RRset which
 /// is not in or below the zone.
-class OutOfZone : public Exception {
+class OutOfZone : public ZoneException {
 public:
     OutOfZone(const char* file, size_t line, const char* what) :
-        isc::Exception(file, line, what) {}
+        ZoneException(file, line, what) {}
 };
 
 /// \brief The base class to search a zone for RRsets



More information about the bind10-changes mailing list