diff --git a/lib/fluent/config/error.rb b/lib/fluent/config/error.rb index f29881a659..2b37333927 100644 --- a/lib/fluent/config/error.rb +++ b/lib/fluent/config/error.rb @@ -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 diff --git a/lib/fluent/registry.rb b/lib/fluent/registry.rb index 32f14bdb6b..9e473c27fd 100644 --- a/lib/fluent/registry.rb +++ b/lib/fluent/registry.rb @@ -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) diff --git a/test/compat/test_parser.rb b/test/compat/test_parser.rb index f5261640ba..8af9a37261 100644 --- a/test/compat/test_parser.rb +++ b/test/compat/test_parser.rb @@ -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 diff --git a/test/plugin/test_filter_parser.rb b/test/plugin/test_filter_parser.rb index 878fef7d6c..45df597400 100644 --- a/test/plugin/test_filter_parser.rb +++ b/test/plugin/test_filter_parser.rb @@ -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 diff --git a/test/plugin/test_filter_stdout.rb b/test/plugin/test_filter_stdout.rb index 5b2711f0a9..49f58ef5d6 100644 --- a/test/plugin/test_filter_stdout.rb +++ b/test/plugin/test_filter_stdout.rb @@ -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 @@ -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 diff --git a/test/plugin/test_out_stdout.rb b/test/plugin/test_out_stdout.rb index 29695b442a..cb87008213 100644 --- a/test/plugin/test_out_stdout.rb +++ b/test/plugin/test_out_stdout.rb @@ -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 @@ -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 diff --git a/test/test_formatter.rb b/test/test_formatter.rb index 9b250841c7..e8e2b26956 100644 --- a/test/test_formatter.rb +++ b/test/test_formatter.rb @@ -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