[Groonga-commit] ranguba/groonga-client at 176beed [master] Support error class

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Mar 28 22:19:34 JST 2014


Kouhei Sutou	2014-03-28 22:19:34 +0900 (Fri, 28 Mar 2014)

  New Revision: 176beed69d824adfb4e891b7534f258ff3203d86
  https://github.com/ranguba/groonga-client/commit/176beed69d824adfb4e891b7534f258ff3203d86

  Message:
    Support error class

  Added files:
    lib/groonga/client/response/error.rb
    test/response/test-error.rb
  Modified files:
    lib/groonga/client/response.rb
    lib/groonga/client/response/base.rb

  Modified: lib/groonga/client/response.rb (+2 -0)
===================================================================
--- lib/groonga/client/response.rb    2014-03-25 18:21:54 +0900 (c6de0a7)
+++ lib/groonga/client/response.rb    2014-03-28 22:19:34 +0900 (4dfe7c2)
@@ -1,5 +1,6 @@
 # -*- coding: utf-8 -*-
 #
+# Copyright (C) 2014  Kouhei Sutou <kou �� clear-code.com>
 # Copyright (C) 2013  Haruka Yoshihara <yoshihara �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
@@ -26,6 +27,7 @@ require "groonga/client/response/column_rename"
 require "groonga/client/response/defrag"
 require "groonga/client/response/delete"
 require "groonga/client/response/dump"
+require "groonga/client/response/error"
 require "groonga/client/response/load"
 require "groonga/client/response/log_level"
 require "groonga/client/response/log_put"

  Modified: lib/groonga/client/response/base.rb (+6 -2)
===================================================================
--- lib/groonga/client/response/base.rb    2014-03-25 18:21:54 +0900 (11c7b26)
+++ lib/groonga/client/response/base.rb    2014-03-28 22:19:34 +0900 (5d059bc)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 #
 # Copyright (C) 2013  Haruka Yoshihara <yoshihara �� clear-code.com>
-# Copyright (C) 2013  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2013-2014  Kouhei Sutou <kou �� clear-code.com>
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -59,7 +59,11 @@ module Groonga
               header = nil
               body = raw_response
             end
-            response = new(command, header, body)
+            if header.nil? or header[0].zero?
+              response = new(command, header, body)
+            else
+              response = Error.new(command, header, body)
+            end
             response.raw = raw_response
             response
           end

  Added: lib/groonga/client/response/error.rb (+27 -0) 100644
===================================================================
--- /dev/null
+++ lib/groonga/client/response/error.rb    2014-03-28 22:19:34 +0900 (43906a7)
@@ -0,0 +1,27 @@
+# Copyright (C) 2014  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "groonga/client/response/base"
+
+module Groonga
+  class Client
+    module Response
+      class Error < Base
+      end
+    end
+  end
+end
+

  Added: test/response/test-error.rb (+39 -0) 100644
===================================================================
--- /dev/null
+++ test/response/test-error.rb    2014-03-28 22:19:34 +0900 (7e2c478)
@@ -0,0 +1,39 @@
+# Copyright (C) 2014  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "response/helper"
+
+class TestResponseError < Test::Unit::TestCase
+  class TestParse < self
+    include TestResponseHelper
+
+    def test_class
+      header = [
+        -22,
+        1396012478.14975,
+        0.00050806999206543,
+        "invalid table name: <Nonexistent>",
+        [
+          ["grn_select", "proc.c", 897],
+        ],
+      ]
+      raw_response = [header].to_json
+
+      response = parse_raw_response("select", raw_response)
+      assert_equal(Groonga::Client::Response::Error, response.class)
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



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