Skip to content

Commit

Permalink
Improve timeperiod validation error messages
Browse files Browse the repository at this point in the history
fixes #8893
  • Loading branch information
gunnarbeutner committed Mar 29, 2015
1 parent a6822fd commit a5c5569
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 34 deletions.
31 changes: 5 additions & 26 deletions lib/icinga/legacytimeperiod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.:
Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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));
Expand All @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions lib/icinga/scheduleddowntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 197,14 @@ void ScheduledDowntime::ValidateRanges(const Dictionary::Ptr& value, const Valid
tm begin_tm, end_tm;
int stride;
LegacyTimePeriod::ParseTimeRange(kv.first, &begin_tm, &end_tm, &stride, &reference);
} catch (std::exception&) {
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("ranges"), "Invalid time specification: " kv.first));
} catch (const std::exception& ex) {
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("ranges"), "Invalid time specification '" kv.first "': " ex.what()));
}

try {
LegacyTimePeriod::ProcessTimeRanges(kv.second, &reference, segments);
} catch (std::exception&) {
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("ranges"), "Invalid time range definition: " kv.first));
} catch (const std::exception& ex) {
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("ranges"), "Invalid time range definition '" kv.second "': " ex.what()));
}
}
}
8 changes: 4 additions & 4 deletions lib/icinga/timeperiod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,14 322,14 @@ void TimePeriod::ValidateRanges(const Dictionary::Ptr& value, const ValidationUt
tm begin_tm, end_tm;
int stride;
LegacyTimePeriod::ParseTimeRange(kv.first, &begin_tm, &end_tm, &stride, &reference);
} catch (std::exception&) {
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("ranges"), "Invalid time specification: " kv.first));
} catch (const std::exception& ex) {
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("ranges"), "Invalid time specification '" kv.first "': " ex.what()));
}

try {
LegacyTimePeriod::ProcessTimeRanges(kv.second, &reference, segments);
} catch (std::exception&) {
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("ranges"), "Invalid time range definition: " kv.second));
} catch (const std::exception& ex) {
BOOST_THROW_EXCEPTION(ValidationError(this, boost::assign::list_of("ranges"), "Invalid time range definition '" kv.second "': " ex.what()));
}
}
}

0 comments on commit a5c5569

Please sign in to comment.