YUKI Hiroshi
null+****@clear*****
Thu Dec 26 15:41:36 JST 2013
YUKI Hiroshi 2013-12-26 15:41:36 +0900 (Thu, 26 Dec 2013) New Revision: 370c7b58ded31645c22c58ff9de431cc9d97b6b3 https://github.com/droonga/fluent-plugin-droonga/commit/370c7b58ded31645c22c58ff9de431cc9d97b6b3 Message: Better handling for unknown commands Modified files: lib/droonga/dispatcher.rb lib/droonga/pluggable.rb Modified: lib/droonga/dispatcher.rb (+9 -0) =================================================================== --- lib/droonga/dispatcher.rb 2013-12-26 15:15:25 +0900 (4d8d1f0) +++ lib/droonga/dispatcher.rb 2013-12-26 15:41:36 +0900 (6eaaa96) @@ -38,6 +38,13 @@ module Droonga end end + class UnknownCommand < BadRequest + def initialize(command, dataset) + super("The command #{command.inspect} is not available " + + "for the dataset #{dataset.inspect}.") + end + end + def initialize(options) @options = options @name = @options[:name] @@ -83,6 +90,8 @@ module Droonga begin assert_valid_message process_input_message(message) + rescue Droonga::Pluggable::UnknownPlugin => error + raise UnknownCommand.new(error.command, message["dataset"]) rescue MessageProcessingError => error reply("statusCode" => error.status_code, "body" => error.response_body) Modified: lib/droonga/pluggable.rb (+9 -4) =================================================================== --- lib/droonga/pluggable.rb 2013-12-26 15:15:25 +0900 (3680a35) +++ lib/droonga/pluggable.rb 2013-12-26 15:41:36 +0900 (1f7ed13) @@ -17,6 +17,14 @@ module Droonga module Pluggable + class UnknownPlugin < StandardError + attr_reader :command + + def initialize(command) + @command = command + end + end + def shutdown $log.trace("#{log_tag}: shutdown: plugin: start") @plugins.each do |plugin| @@ -33,10 +41,7 @@ module Droonga plugin = find_plugin(command) $log.trace("#{log_tag}: process: start: <#{command}>", :plugin => plugin.class) - if plugin.nil? - raise "unknown plugin: <#{command}>: " + - "TODO: improve error handling" - end + raise UnknownPlugin.new(command) if plugin.nil? plugin.process(command, *arguments) $log.trace("#{log_tag}: process: done: <#{command}>", :plugin => plugin.class) -------------- next part -------------- HTML����������������������������...Download