[Groonga-commit] droonga/fluent-plugin-droonga at 1e6e8f0 [master] Handle error while distributing correctly

Back to archive index

YUKI Hiroshi null+****@clear*****
Thu Dec 26 16:25:49 JST 2013


YUKI Hiroshi	2013-12-26 16:25:49 +0900 (Thu, 26 Dec 2013)

  New Revision: 1e6e8f035014206ccaab88371b0f715e80ba1ca0
  https://github.com/droonga/fluent-plugin-droonga/commit/1e6e8f035014206ccaab88371b0f715e80ba1ca0

  Message:
    Handle error while distributing correctly

  Modified files:
    lib/droonga/catalog.rb
    lib/droonga/dispatcher.rb
    lib/droonga/distributor_plugin.rb
    lib/droonga/handler_plugin.rb
    lib/droonga/plugin.rb

  Modified: lib/droonga/catalog.rb (+2 -4)
===================================================================
--- lib/droonga/catalog.rb    2013-12-26 16:00:05 +0900 (8b7f2af)
+++ lib/droonga/catalog.rb    2013-12-26 16:25:49 +0900 (6fbe759)
@@ -27,11 +27,9 @@ module Droonga
   end
 
   class Catalog
-    class UnknownDataset < StandardError
-      attr_reader :dataset
-
+    class UnknownDataset < NotFound
       def initialize(dataset)
-        @dataset = dataset
+        super("The dataset #{dataset.inspect} does not exist.")
       end
     end
 

  Modified: lib/droonga/dispatcher.rb (+2 -15)
===================================================================
--- lib/droonga/dispatcher.rb    2013-12-26 16:00:05 +0900 (9d303a0)
+++ lib/droonga/dispatcher.rb    2013-12-26 16:25:49 +0900 (17907c3)
@@ -38,12 +38,6 @@ module Droonga
       end
     end
 
-    class UnknownDataset < NotFound
-      def initialize(dataset)
-        super("The dataset #{dataset.inspect} does not exist.")
-      end
-    end
-
     class UnknownCommand < BadRequest
       def initialize(command, dataset)
         super("The command #{command.inspect} is not available " +
@@ -217,15 +211,8 @@ module Droonga
     def process_input_message(message)
       adapted_message = @input_adapter.adapt(message)
       @distributor.process(adapted_message["type"], adapted_message)
-    rescue StandardError => error
-      case error
-      when Droonga::Catalog::UnknownDataset
-        raise UnknownDataset.new(error.dataset)
-      when Droonga::Pluggable::UnknownPlugin
-        raise UnknownCommand.new(error.command, message["dataset"])
-      else
-        raise error
-      end
+    rescue Droonga::Pluggable::UnknownPlugin => error
+      raise UnknownCommand.new(error.command, message["dataset"])
     end
 
     def assert_valid_message

  Modified: lib/droonga/distributor_plugin.rb (+9 -0)
===================================================================
--- lib/droonga/distributor_plugin.rb    2013-12-26 16:00:05 +0900 (691d872)
+++ lib/droonga/distributor_plugin.rb    2013-12-26 16:25:49 +0900 (cb19d55)
@@ -54,5 +54,14 @@ module Droonga
       }]
       distribute(distribute_message)
     end
+
+    private
+    def process_error(command, error, arguments)
+      if error.is_a?(MessageProcessingError)
+        raise error
+      else
+        super
+      end
+    end
   end
 end

  Modified: lib/droonga/handler_plugin.rb (+4 -4)
===================================================================
--- lib/droonga/handler_plugin.rb    2013-12-26 16:00:05 +0900 (5eae2c7)
+++ lib/droonga/handler_plugin.rb    2013-12-26 16:25:49 +0900 (96727a0)
@@ -33,11 +33,11 @@ module Droonga
     end
 
     private
-    def run_command(command, message, messenger)
-      begin
-        super
-      rescue MessageProcessingError => error
+    def process_error(command, error, arguments)
+      if error.is_a?(MessageProcessingError)
         messenger.error(error.status_code, error.response_body)
+      else
+        super
       end
     end
   end

  Modified: lib/droonga/plugin.rb (+6 -6)
===================================================================
--- lib/droonga/plugin.rb    2013-12-26 16:00:05 +0900 (f5e0cbd)
+++ lib/droonga/plugin.rb    2013-12-26 16:25:49 +0900 (986bc50)
@@ -33,16 +33,16 @@ module Droonga
     end
 
     def process(command, *arguments)
-      run_command(command, *arguments)
+      __send__(self.class.method_name(command), *arguments)
     rescue => exception
-      Logger.error("error while processing #{command}",
-                   exception,
-                   arguments: arguments)
+      process_error(command, exception, arguments)
     end
     
     private
-    def run_command(command, *arguments)
-      __send__(self.class.method_name(command), *arguments)
+    def process_error(command, error, arguments)
+      Logger.error("error while processing #{command}",
+                   error,
+                   :arguments => arguments)
     end
   end
 end
-------------- next part --------------
HTML����������������������������...
다운로드 



More information about the Groonga-commit mailing list
Back to archive index