[Groonga-commit] groonga/groonga at 6fea0a2 [master] mruby: add convenience method to handler error

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Aug 7 23:46:13 JST 2014


Kouhei Sutou	2014-08-07 23:46:13 +0900 (Thu, 07 Aug 2014)

  New Revision: 6fea0a21712edb1994e913fc888bf617ab1a41b5
  https://github.com/groonga/groonga/commit/6fea0a21712edb1994e913fc888bf617ab1a41b5

  Message:
    mruby: add convenience method to handler error

  Modified files:
    lib/mrb/scripts/context.rb
    lib/mrb/scripts/expression.rb

  Modified: lib/mrb/scripts/context.rb (+12 -0)
===================================================================
--- lib/mrb/scripts/context.rb    2014-08-07 23:15:18 +0900 (3d9f923)
+++ lib/mrb/scripts/context.rb    2014-08-07 23:46:13 +0900 (f35448d)
@@ -1,4 +1,16 @@
 module Groonga
   class Context
+    def guard(fallback=nil)
+      begin
+        yield
+      rescue => error
+        backtrace = error.backtrace
+        puts "#{error.class}: #{error.message}"
+        backtrace.each do |entry|
+          puts entry
+        end
+        fallback
+      end
+    end
   end
 end

  Modified: lib/mrb/scripts/expression.rb (+1 -8)
===================================================================
--- lib/mrb/scripts/expression.rb    2014-08-07 23:15:18 +0900 (dbeac49)
+++ lib/mrb/scripts/expression.rb    2014-08-07 23:46:13 +0900 (5e939d5)
@@ -1,16 +1,9 @@
 module Groonga
   class Expression
     def build_scan_info(op, size)
-      begin
+      Context.instance.guard do
         builder = ScanInfoBuilder.new(self, op, size)
         builder.build
-      rescue => error
-        backtrace = error.backtrace
-        puts "#{error.class}: #{error.message}"
-        backtrace.each do |entry|
-          puts entry
-        end
-        nil
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
下載 



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