Skip to content

Commit

Permalink
Merge pull request #1202 from fluent/raise-configuration-errors-for-m…
Browse files Browse the repository at this point in the history
…issing-type

fix to raise ConfigError for type missing, and its tests
  • Loading branch information
tagomoris authored Sep 2, 2016
2 parents 9c908df + 8c04641 commit 81b4330
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/fluent/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def configure(conf)
conf.elements('filter', 'match').each { |e|
pattern = e.arg.empty? ? '**' : e.arg
type = e['@type']
raise ConfigError, "Missing '@type' parameter on <#{e.name}> directive" unless type
if e.name == 'filter'
add_filter(type, pattern, e)
else
Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def configure(conf)
else
conf.elements(name: 'source').each { |e|
type = e['@type']
raise ConfigError, "Missing 'type' parameter on <source> directive" unless type
raise ConfigError, "Missing '@type' parameter on <source> directive" unless type
add_source(type, e)
}
end
Expand Down
42 changes: 42 additions & 0 deletions test/test_root_agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,48 @@ def configure_ra(conf_str)
assert_nil ra.error_collector
end

test 'raises configuration error for missing type of source' do
conf = <<-EOC
<source>
</source>
EOC
errmsg = "Missing '@type' parameter on <source> directive"
assert_raise Fluent::ConfigError.new(errmsg) do
configure_ra(conf)
end
end

test 'raises configuration error for missing type of match' do
conf = <<-EOC
<source>
@type test_in
</source>
<match *.**>
</match>
EOC
errmsg = "Missing '@type' parameter on <match> directive"
assert_raise Fluent::ConfigError.new(errmsg) do
configure_ra(conf)
end
end

test 'raises configuration error for missing type of filter' do
conf = <<-EOC
<source>
@type test_in
</source>
<filter *.**>
</filter>
<match *.**>
@type test_out
</match>
EOC
errmsg = "Missing '@type' parameter on <filter> directive"
assert_raise Fluent::ConfigError.new(errmsg) do
configure_ra(conf)
end
end

test 'with plugins' do
# check @type and type in one configuration
conf = <<-EOC
Expand Down

0 comments on commit 81b4330

Please sign in to comment.