]> granicus.if.org Git - icinga2/commitdiff
Improve timeperiod validation error messages
authorGunnar Beutner <gunnar@beutner.name>
Sun, 29 Mar 2015 06:13:11 +0000 (08:13 +0200)
committerGunnar Beutner <gunnar@beutner.name>
Tue, 31 Mar 2015 06:49:55 +0000 (08:49 +0200)
fixes #8893

lib/icinga/legacytimeperiod.cpp
lib/icinga/scheduleddowntime.cpp
lib/icinga/timeperiod.cpp

index b346d3bc0011c5eaa746819aa5ee8afb916ee0b0..5c7d64b5f4cd277e9caacf79369ca8ac372d0df1 100644 (file)
@@ -289,11 +289,7 @@ void LegacyTimePeriod::ParseTimeRange(const String& timerange, tm *begin, tm *en
                String second = def.SubStr(pos + 1);
                second.Trim();
 
-               try {
-                       ParseTimeSpec(first, begin, NULL, reference);
-               } catch (std::exception&) {
-                       throw;
-               }
+               ParseTimeSpec(first, begin, NULL, reference);
 
                /* If the second definition starts with a number we need
                 * to add the first word from the first definition, e.g.:
@@ -314,17 +310,9 @@ void LegacyTimePeriod::ParseTimeRange(const String& timerange, tm *begin, tm *en
                        second = first.SubStr(0, xpos + 1) + second;
                }
 
-               try {
-                       ParseTimeSpec(second, NULL, end, reference);
-               } catch (std::exception&) {
-                       throw;
-               }
+               ParseTimeSpec(second, NULL, end, reference);
        } else {
-               try {
-                       ParseTimeSpec(def, begin, end, reference);
-               } catch (std::exception&) {
-                       throw;
-               }
+               ParseTimeSpec(def, begin, end, reference);
        }
 }
 
@@ -381,11 +369,7 @@ Dictionary::Ptr LegacyTimePeriod::ProcessTimeRange(const String& timestamp, tm *
 {
        tm begin, end;
 
-       try {
-               ProcessTimeRangeRaw(timestamp, reference, &begin, &end);
-       } catch (std::exception&) {
-               throw;
-       }
+       ProcessTimeRangeRaw(timestamp, reference, &begin, &end);
 
        Dictionary::Ptr segment = new Dictionary();
        segment->Set("begin", (long)mktime(&begin));
@@ -400,12 +384,7 @@ void LegacyTimePeriod::ProcessTimeRanges(const String& timeranges, tm *reference
        boost::algorithm::split(ranges, timeranges, boost::is_any_of(","));
 
        BOOST_FOREACH(const String& range, ranges) {
-               Dictionary::Ptr segment;
-               try {
-                       segment = ProcessTimeRange(range, reference);
-               } catch (std::exception&) {
-                       throw;
-               }
+               Dictionary::Ptr segment = ProcessTimeRange(range, reference);
 
                if (segment->Get("begin") >= segment->Get("end"))
                        continue;
index 446e252812f0eb3e2d7ccb6c83370e6198232721..6c4e7986eb7398a8727cdb93523dfd50f71b6f05 100644 (file)
@@ -199,16 +199,16 @@ void ScheduledDowntime::ValidateRanges(const String& location, const ScheduledDo
                        tm begin_tm, end_tm;
                        int stride;
                        LegacyTimePeriod::ParseTimeRange(kv.first, &begin_tm, &end_tm, &stride, &reference);
-               } catch (std::exception&) {
+               } catch (const std::exception& ex) {
                        BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
-                           location + ": Invalid time specification.", object->GetDebugInfo()));
+                           location + ": Invalid time specification '" + kv.first + "': " + ex.what(), object->GetDebugInfo()));
                }
 
                try {
                        LegacyTimePeriod::ProcessTimeRanges(kv.second, &reference, segments);
-               } catch (std::exception&) {
+               } catch (const std::exception& ex) {
                        BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
-                           location + ": Invalid time range definition.", object->GetDebugInfo()));
+                           location + ": Invalid time range definition '" + kv.second + "': " + ex.what(), object->GetDebugInfo()));
                }
        }
 }
index 825e52e7cf0be99b44acbe7db87985bbf450b46a..1337390dafea73e4d44d2c464017332e44f29f6f 100644 (file)
@@ -324,16 +324,16 @@ void TimePeriod::ValidateRanges(const String& location, const TimePeriod::Ptr& o
                        tm begin_tm, end_tm;
                        int stride;
                        LegacyTimePeriod::ParseTimeRange(kv.first, &begin_tm, &end_tm, &stride, &reference);
-               } catch (std::exception&) {
+               } catch (const std::exception& ex) {
                        BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
-                           location + ": Invalid time specification.", object->GetDebugInfo()));
+                           location + ": Invalid time specification '" + kv.first + "': " + ex.what(), object->GetDebugInfo()));
                }
 
                try {
                        LegacyTimePeriod::ProcessTimeRanges(kv.second, &reference, segments);
-               } catch (std::exception&) {
+               } catch (const std::exception& ex) {
                        BOOST_THROW_EXCEPTION(ScriptError("Validation failed for " +
-                           location + ": Invalid time range definition.", object->GetDebugInfo()));
+                           location + ": Invalid time range definition '" + kv.second + "': " + ex.what(), object->GetDebugInfo()));
                }
        }
 }