groonga-client 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/doc/text/news.md +12 -0
- data/lib/groonga/client/error.rb +30 -0
- data/lib/groonga/client/request/error.rb +3 -17
- data/lib/groonga/client/response/base.rb +9 -2
- data/lib/groonga/client/version.rb +2 -2
- data/test/response/test-base.rb +15 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55cca8c755088db978d5f1064f0fa737289074b7ad06cfe248b42cf44032ad49
|
4
|
+
data.tar.gz: c6d8c400c8c14ab86955480743bdc9c14cf7a4c34f2b05b3dbbcda62a4a37baf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2311b2192456fdec99cd357e1f281e3d4242aa4ab0cdc2f4fb274bc88434a5fd158cf36201badc90ddacd7e9e00d20ee5d32f0e23244a8560d39193c3b33947e
|
7
|
+
data.tar.gz: aead1e7ea6c6225ff0b4a1c802857527a154556fbfaa055f3b300fc34eeed482ad3f845393eef85e3960ec1fea588129fcec6d314625efb945d16b8b64e7d2db
|
data/doc/text/news.md
CHANGED
data/lib/groonga/client/error.rb
CHANGED
@@ -18,5 +18,35 @@ module Groonga
|
|
18
18
|
class Client
|
19
19
|
class Error < StandardError
|
20
20
|
end
|
21
|
+
|
22
|
+
class ErrorResponse < Error
|
23
|
+
attr_reader :response
|
24
|
+
def initialize(response)
|
25
|
+
@response = response
|
26
|
+
command = @response.command
|
27
|
+
status_code = @response.status_code
|
28
|
+
error_message = @response.error_message
|
29
|
+
message = "failed to execute: "
|
30
|
+
message << "#{command.command_name}: #{status_code}: "
|
31
|
+
message << "<#{error_message}>: "
|
32
|
+
message << command.to_command_format
|
33
|
+
super(message)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class InvalidResponse < Error
|
38
|
+
attr_reader :command
|
39
|
+
attr_reader :raw_response
|
40
|
+
def initialize(command, raw_response, error_message)
|
41
|
+
@command = command
|
42
|
+
@raw_response = raw_response
|
43
|
+
message = +"invalid response: "
|
44
|
+
message << "#{command.command_name}: "
|
45
|
+
message << "#{error_message}: "
|
46
|
+
message << "<#{command.to_command_format}>: "
|
47
|
+
message << "<#{raw_response}>"
|
48
|
+
super(message)
|
49
|
+
end
|
50
|
+
end
|
21
51
|
end
|
22
52
|
end
|
@@ -19,23 +19,9 @@ require "groonga/client/error"
|
|
19
19
|
module Groonga
|
20
20
|
class Client
|
21
21
|
module Request
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
class ErrorResponse < Error
|
26
|
-
attr_reader :response
|
27
|
-
def initialize(response)
|
28
|
-
@response = response
|
29
|
-
command = @response.command
|
30
|
-
status_code = @response.status_code
|
31
|
-
error_message = @response.error_message
|
32
|
-
message = "failed to execute: "
|
33
|
-
message << "#{command.command_name}: #{status_code}: "
|
34
|
-
message << "<#{error_message}>: "
|
35
|
-
message << command.to_command_format
|
36
|
-
super(message)
|
37
|
-
end
|
38
|
-
end
|
22
|
+
# For backward compatibility
|
23
|
+
Error = Client::Error
|
24
|
+
ErrorResponse = Client::ErrorResponse
|
39
25
|
end
|
40
26
|
end
|
41
27
|
end
|
@@ -73,9 +73,16 @@ module Groonga
|
|
73
73
|
callback = command["callback"]
|
74
74
|
if callback and
|
75
75
|
/\A#{Regexp.escape(callback)}\((.+)\);\z/ =~ raw_response
|
76
|
-
|
76
|
+
json = $1
|
77
77
|
else
|
78
|
-
|
78
|
+
json = raw_response
|
79
|
+
end
|
80
|
+
begin
|
81
|
+
response = JSON.parse(json)
|
82
|
+
rescue JSON::ParserError => error
|
83
|
+
raise InvalidResponse.new(command,
|
84
|
+
raw_response,
|
85
|
+
"invalid JSON: #{error}")
|
79
86
|
end
|
80
87
|
if response.is_a?(::Array)
|
81
88
|
header, body = response
|
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2013-
|
1
|
+
# Copyright (C) 2013-2024 Sutou Kouhei <kou@clear-code.com>
|
2
2
|
#
|
3
3
|
# This library is free software; you can redistribute it and/or
|
4
4
|
# modify it under the terms of the GNU Lesser General Public
|
@@ -16,6 +16,6 @@
|
|
16
16
|
|
17
17
|
module Groonga
|
18
18
|
class Client
|
19
|
-
VERSION = "0.
|
19
|
+
VERSION = "0.7.0"
|
20
20
|
end
|
21
21
|
end
|
data/test/response/test-base.rb
CHANGED
@@ -222,5 +222,20 @@ class TestResponseBase < Test::Unit::TestCase
|
|
222
222
|
response = Groonga::Client::Response::Base.parse(command, raw_response)
|
223
223
|
assert_equal(1396012478, response.body["start_time"])
|
224
224
|
end
|
225
|
+
|
226
|
+
def test_invalid_json
|
227
|
+
command = Groonga::Command::Base.new("cancel")
|
228
|
+
raw_response = '["header", :{"return_code":-77}}'
|
229
|
+
begin
|
230
|
+
JSON.parse(raw_response)
|
231
|
+
rescue JSON::ParserError => error
|
232
|
+
parse_error_message = "invalid JSON: #{error}"
|
233
|
+
end
|
234
|
+
error = Groonga::Client::InvalidResponse.new(command, raw_response, parse_error_message)
|
235
|
+
|
236
|
+
assert_raise(error) do
|
237
|
+
Groonga::Client::Response::Base.parse(command, raw_response)
|
238
|
+
end
|
239
|
+
end
|
225
240
|
end
|
226
241
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: groonga-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Haruka Yoshihara
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
- Kosuke Asami
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-
|
12
|
+
date: 2024-10-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: gqtp
|