[Groonga-commit] groonga/groonga-command [master] Wrap Yajl::ParseError

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Nov 27 17:46:54 JST 2012


Kouhei Sutou	2012-11-27 17:46:54 +0900 (Tue, 27 Nov 2012)

  New Revision: 0ef667c60be305b6dd2b4260c49aaa816c529ca7
  https://github.com/groonga/groonga-command/commit/0ef667c60be305b6dd2b4260c49aaa816c529ca7

  Log:
    Wrap Yajl::ParseError

  Modified files:
    lib/groonga/command/parser.rb

  Modified: lib/groonga/command/parser.rb (+14 -4)
===================================================================
--- lib/groonga/command/parser.rb    2012-11-27 17:28:32 +0900 (705d137)
+++ lib/groonga/command/parser.rb    2012-11-27 17:46:54 +0900 (0a715b7)
@@ -217,14 +217,12 @@ module Groonga
             end
           end
           @buffer = rest
-          @command.original_source << json
-          @json_parser << json
+          parse_json(json)
           if separator.empty?
             throw(tag)
           else
-            @command.original_source << separator
             @load_value_completed = false
-            @json_parser << separator
+            parse_json(separator)
           end
         else
           spaces, start_json, rest =****@buffe*****("[")
@@ -248,6 +246,18 @@ module Groonga
         end
       end
 
+      def parse_json(json)
+        @command.original_source << json
+        begin
+          @json_parser << json
+        rescue Yajl::ParseError
+          message = "Invalid JSON: #{$!.message}: <#{json}>:\n"
+          message << @command.original_source
+          raise ParseError.new(message)
+        else
+        end
+      end
+
       def consume_line(tag)
         current_line, separator, rest =****@buffe*****(/\r?\n/)
         throw(tag) if separator.empty?
-------------- next part --------------
HTML����������������������������...
Télécharger 



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