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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6da9f45867a1b6ba3343309e8935b8efdc8b9d3c8d35d7dec702738b38829a7
4
- data.tar.gz: 29178875a3d700f8b17c2c1cfab67c37baf86a811af258e5bb2069916d90de24
3
+ metadata.gz: 55cca8c755088db978d5f1064f0fa737289074b7ad06cfe248b42cf44032ad49
4
+ data.tar.gz: c6d8c400c8c14ab86955480743bdc9c14cf7a4c34f2b05b3dbbcda62a4a37baf
5
5
  SHA512:
6
- metadata.gz: b351339a18628c2230cdc20714cbc82517cbc46618860a3cac0f31d3a75ffaae2181771affbe17a9a61575cecbc071a284f040436fa59efe30450b82f12d8cc3
7
- data.tar.gz: a8c6326cbfb48225dc799915867c3757c05d824f02ec79fa510407d306431fba0745c5aba7a1ad1c8ba5382e58b97c0e469299ea8c5e8c855ef9e211f2538021
6
+ metadata.gz: 2311b2192456fdec99cd357e1f281e3d4242aa4ab0cdc2f4fb274bc88434a5fd158cf36201badc90ddacd7e9e00d20ee5d32f0e23244a8560d39193c3b33947e
7
+ data.tar.gz: aead1e7ea6c6225ff0b4a1c802857527a154556fbfaa055f3b300fc34eeed482ad3f845393eef85e3960ec1fea588129fcec6d314625efb945d16b8b64e7d2db
data/doc/text/news.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # NEWS
2
2
 
3
+ ## 0.7.0 - 2024-10-16
4
+
5
+ ### Improvements
6
+
7
+ * Improved error message on JSON parse error.
8
+ * GH-32
9
+ * Patch by Abe Tomoaki
10
+
11
+ ### Thanks
12
+
13
+ * Abe Tomoaki
14
+
3
15
  ## 0.6.9 - 2024-04-10
4
16
 
5
17
  ### Improvements
@@ -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
- class Error < Client::Error
23
- end
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
- response = JSON.parse($1)
76
+ json = $1
77
77
  else
78
- response = JSON.parse(raw_response)
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-2023 Sutou Kouhei <kou@clear-code.com>
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.6.9"
19
+ VERSION = "0.7.0"
20
20
  end
21
21
  end
@@ -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.6.9
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-04-10 00:00:00.000000000 Z
12
+ date: 2024-10-16 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: gqtp