Skip to content

Commit 8351fbd

Browse files
wiibaaSuyog Rao
authored and
Suyog Rao
committed
filter/mutate raise configError in register
Closes elastic#1656
1 parent 2f12d38 commit 8351fbd

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

lib/logstash/filters/mutate.rb

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,18 @@ def register
177177
# TODO(sissel): Validate conversion requests if provided.
178178
@convert.nil? or @convert.each do |field, type|
179179
if !valid_conversions.include?(type)
180-
@logger.error("Invalid conversion type",
181-
"type" => type, "expected one of" => valid_types)
182-
# TODO(sissel): It's 2011, man, let's actually make like.. a proper
183-
# 'configuration broken' exception
184-
raise "Bad configuration, aborting."
180+
raise LogStash::ConfigurationError, I18n.t("logstash.agent.configuration.invalid_plugin_register",
181+
:plugin => "filter", :type => "mutate",
182+
:error => "Invalid conversion type '#{type}', expected one of '#{valid_conversions.join(',')}'")
185183
end
186184
end # @convert.each
187185

188186
@gsub_parsed = []
189187
@gsub.nil? or @gsub.each_slice(3) do |field, needle, replacement|
190188
if [field, needle, replacement].any? {|n| n.nil?}
191-
@logger.error("Invalid gsub configuration. gsub has to define 3 elements per config entry", :field => field, :needle => needle, :replacement => replacement)
192-
raise "Bad configuration, aborting."
189+
raise LogStash::ConfigurationError, I18n.t("logstash.agent.configuration.invalid_plugin_register",
190+
:plugin => "filter", :type => "mutate",
191+
:error => "Invalid gsub configuration #{[field, needle, replacement]}. gsub requires 3 non-nil elements per config entry")
193192
end
194193

195194
@gsub_parsed << {

spec/filters/mutate.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,35 @@
66
describe LogStash::Filters::Mutate do
77
extend LogStash::RSpec
88

9+
context "config validation" do
10+
describe "invalid convert type should raise a configuration error" do
11+
config <<-CONFIG
12+
filter {
13+
mutate {
14+
convert => [ "message", "int"] //should be integer
15+
}
16+
}
17+
CONFIG
18+
19+
sample "not_really_important" do
20+
insist {subject}.raises LogStash::ConfigurationError
21+
end
22+
end
23+
describe "invalid gsub triad should raise a configuration error" do
24+
config <<-CONFIG
25+
filter {
26+
mutate {
27+
gsub => [ "message", "toreplace"]
28+
}
29+
}
30+
CONFIG
31+
32+
sample "not_really_important" do
33+
insist {subject}.raises LogStash::ConfigurationError
34+
end
35+
end
36+
end
37+
938
describe "basics" do
1039
config <<-CONFIG
1140
filter {

0 commit comments

Comments
 (0)