[Groonga-commit] groonga/groonga at 5cdc1ab [master] mruby: record error while building scan_info

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Aug 7 23:49:00 JST 2014


Kouhei Sutou	2014-08-07 23:49:00 +0900 (Thu, 07 Aug 2014)

  New Revision: 5cdc1ab748b473af6f002fa1e95c0bc464fc3479
  https://github.com/groonga/groonga/commit/5cdc1ab748b473af6f002fa1e95c0bc464fc3479

  Message:
    mruby: record error while building scan_info

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

  Modified: lib/mrb/scripts/context.rb (+20 -0)
===================================================================
--- lib/mrb/scripts/context.rb    2014-08-07 23:47:42 +0900 (f35448d)
+++ lib/mrb/scripts/context.rb    2014-08-07 23:49:00 +0900 (a4b8eda)
@@ -12,5 +12,25 @@ module Groonga
         fallback
       end
     end
+
+    def logger
+      @logger ||= Logger.new
+    end
+
+    def record_error(rc, error)
+      rc = RC.find(rc) if rc.is_a?(Symbol)
+      self.rc = rc.to_i
+      self.error_level = ErrorLevel.find(:error).to_i
+
+      backtrace = error.backtrace
+      entry = backtrace.first
+      match_data = /:(\d+):/.match(entry)
+      self.error_file = match_data.pre_match
+      self.error_line = match_data[1].to_i
+      self.error_method = match_data.post_match.gsub(/^in /, "")
+      self.error_message = error.message
+
+      logger.log_error(error)
+    end
   end
 end

  Modified: lib/mrb/scripts/expression.rb (+4 -1)
===================================================================
--- lib/mrb/scripts/expression.rb    2014-08-07 23:47:42 +0900 (5e939d5)
+++ lib/mrb/scripts/expression.rb    2014-08-07 23:49:00 +0900 (29290e2)
@@ -1,9 +1,12 @@
 module Groonga
   class Expression
     def build_scan_info(op, size)
-      Context.instance.guard do
+      begin
         builder = ScanInfoBuilder.new(self, op, size)
         builder.build
+      rescue => error
+        Context.instance.record_error(:invalid_argument, error)
+        nil
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
Download 



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