Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more concrete error class on plugin not found #3604

Merged
merged 1 commit into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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