Module: check_mk
Branch: master
Commit: 699f590f17187a664cc343c886666cf0e8f1e7b9
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=699f590f17187a…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Nov 20 11:39:20 2017 +0100
Centralize error handling a bit more.
Change-Id: I829603e3fb5324ec1770e50a753b10a6f787953b
---
livestatus/src/Query.cc | 13 ++-----------
livestatus/src/StatsColumn.cc | 7 ++++++-
2 files changed, 8 insertions(+), 12 deletions(-)
diff --git a/livestatus/src/Query.cc b/livestatus/src/Query.cc
index 4171ee9..57838fc 100644
--- a/livestatus/src/Query.cc
+++ b/livestatus/src/Query.cc
@@ -261,12 +261,7 @@ void Query::parseStatsAndOrLine(char *line, LogicalOperator op) {
" filters, but only " + std::to_string(i) + " " +
(i == 1 ? "is" : "are") + " on stack");
}
- auto &col = _stats_columns.back();
- if (col->operation() != StatsOperation::count) {
- throw std::runtime_error(
- "only valid on Stats: headers of filter type");
- }
- subfilters.push_back(col->stealFilter());
+ subfilters.push_back(_stats_columns.back()->stealFilter());
_stats_columns.pop_back();
}
_stats_columns.push_back(std::make_unique<StatsColumn>(
@@ -279,11 +274,7 @@ void Query::parseStatsNegateLine(char *line) {
throw("error combining filters for table '" + _table->name() +
"': expected 1 filters, but only 0 are on stack");
}
- auto &col = _stats_columns.back();
- if (col->operation() != StatsOperation::count) {
- throw std::runtime_error("only valid on Stats: headers of filter
type");
- }
- auto to_negate = col->stealFilter();
+ auto to_negate = _stats_columns.back()->stealFilter();
_stats_columns.pop_back();
_stats_columns.push_back(std::make_unique<StatsColumn>(
nullptr, to_negate->negate(), StatsOperation::count));
diff --git a/livestatus/src/StatsColumn.cc b/livestatus/src/StatsColumn.cc
index bd75909..cffc974 100644
--- a/livestatus/src/StatsColumn.cc
+++ b/livestatus/src/StatsColumn.cc
@@ -34,7 +34,12 @@
StatsColumn::StatsColumn(Column *c, std::unique_ptr<Filter> f, StatsOperation o)
: _column(c), _filter(std::move(f)), _operation(o) {}
-std::unique_ptr<Filter> StatsColumn::stealFilter() { return move(_filter); }
+std::unique_ptr<Filter> StatsColumn::stealFilter() {
+ if (_operation != StatsOperation::count) {
+ throw std::runtime_error("not a counting aggregator");
+ }
+ return move(_filter);
+}
std::unique_ptr<Aggregator> StatsColumn::createAggregator(
Logger *logger) const {