Skip to content

Commit

Permalink
Merge pull request #3604 from fluent/separate-error-class-on-not-foun…
Browse files Browse the repository at this point in the history
…d-plugin

Use more concrete error class on plugin not found
  • Loading branch information
ashie authored Jan 19, 2022
2 parents c297456 + 667d7e3 commit a606033
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 8 deletions.
12 changes: 12 additions & 0 deletions lib/fluent/config/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,16 @@ class SetNil < Exception

class SetDefault < Exception
end

class NotFoundPluginError < ConfigError
attr_reader :type, :kind

def initialize(msg, type: nil, kind: nil)
@msg = msg
@type = type
@kind = kind

super(msg)
end
end
end
3 changes: 2 additions & 1 deletion lib/fluent/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ def lookup(type)
if value = @map[type]
return value
end
raise ConfigError, "Unknown #{@kind} plugin '#{type}'. Run 'gem search -rd fluent-plugin' to find plugins" # TODO error class
raise NotFoundPluginError.new("Unknown #{@kind} plugin '#{type}'. Run 'gem search -rd fluent-plugin' to find plugins",
kind: @kind, type: type)
end

def reverse_lookup(value)
Expand Down
2 changes: 1 addition & 1 deletion test/compat/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def parse(text)
Fluent::TextParser.register_template('multi_event_test', Proc.new { MultiEventTestParser.new })

def test_lookup_unknown_format
assert_raise Fluent::ConfigError do
assert_raise Fluent::NotFoundPluginError do
Fluent::Plugin.new_parser('unknown')
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/plugin/test_filter_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def test_configure
assert_raise(Fluent::ConfigError) {
create_driver('')
}
assert_raise(Fluent::ConfigError) {
assert_raise(Fluent::NotFoundPluginError) {
create_driver %[
key_name foo
<parse>
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/test_filter_stdout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def test_output_type(data)
end

def test_invalid_output_type
assert_raise(Fluent::ConfigError) do
assert_raise(Fluent::NotFoundPluginError) do
d = create_driver(CONFIG + config_element("", "", { "output_type" => "foo" }))
d.run {}
end
Expand Down Expand Up @@ -139,7 +139,7 @@ def test_output_type(data)
def test_invalid_output_type
conf = config_element
conf.elements << config_element("format", "", { "@type" => "stdout", "output_type" => "foo" })
assert_raise(Fluent::ConfigError) do
assert_raise(Fluent::NotFoundPluginError) do
d = create_driver(conf)
d.run {}
end
Expand Down
4 changes: 2 additions & 2 deletions test/plugin/test_out_stdout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def create_driver(conf = CONFIG)
assert_kind_of Fluent::Plugin::StdoutFormatter, d.instance.formatter
assert_equal 'hash', d.instance.formatter.output_type

assert_raise(Fluent::ConfigError) do
assert_raise(Fluent::NotFoundPluginError) do
d = create_driver(CONFIG + "\noutput_type foo")
end
end
Expand Down Expand Up @@ -126,7 +126,7 @@ def create_driver(conf = CONFIG)
assert_kind_of Fluent::Plugin::StdoutFormatter, d.instance.formatter
assert_equal 'hash', d.instance.formatter.output_type

assert_raise(Fluent::ConfigError) do
assert_raise(Fluent::NotFoundPluginError) do
create_driver(config_element("ROOT", "", {"output_type" => "foo"}, [config_element("buffer")]))
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ class FormatterLookupTest < ::Test::Unit::TestCase
include FormatterTest

def test_unknown_format
assert_raise ConfigError do
assert_raise NotFoundPluginError do
Fluent::Plugin.new_formatter('unknown')
end
end
Expand Down

0 comments on commit a606033

Please sign in to comment.