groonga-client 0.6.8 → 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: 5eff655174ca6884d2bfb486f8bbdf482f1eb01f9cccc0340670cce03a6233ea
4
- data.tar.gz: 3b98a877d32035990fa3f955fbd540b9e20ad9b5757c86dcdc855114c82713eb
3
+ metadata.gz: 55cca8c755088db978d5f1064f0fa737289074b7ad06cfe248b42cf44032ad49
4
+ data.tar.gz: c6d8c400c8c14ab86955480743bdc9c14cf7a4c34f2b05b3dbbcda62a4a37baf
5
5
  SHA512:
6
- metadata.gz: 0ab452bca052b4258c0271960c7ff9689cea77cbb2b642f224195809361bdf6d7e18ec1347d01bb558aed0496f0e970f97d1df9ef0b5743a8d861a9e4dcd1639
7
- data.tar.gz: 186fa2f3260fe48bc56295fed075fc9617f9b9f559390f63a2a3ca7f37cd75e9db07ab0aae63959ed605c44656cdb878896381068fad6d81c96d15715caf3aab
6
+ metadata.gz: 2311b2192456fdec99cd357e1f281e3d4242aa4ab0cdc2f4fb274bc88434a5fd158cf36201badc90ddacd7e9e00d20ee5d32f0e23244a8560d39193c3b33947e
7
+ data.tar.gz: aead1e7ea6c6225ff0b4a1c802857527a154556fbfaa055f3b300fc34eeed482ad3f845393eef85e3960ec1fea588129fcec6d314625efb945d16b8b64e7d2db
data/doc/text/news.md CHANGED
@@ -1,5 +1,23 @@
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
+
15
+ ## 0.6.9 - 2024-04-10
16
+
17
+ ### Improvements
18
+
19
+ * HTTP: Added support for request cancel.
20
+
3
21
  ## 0.6.8 - 2023-11-07
4
22
 
5
23
  ### 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
@@ -66,15 +66,19 @@ module Groonga
66
66
  http.start do
67
67
  http.read_timeout = read_timeout
68
68
  response = send_request(http, command)
69
+ body = response.body
69
70
  case response
70
- when Net::HTTPSuccess, Net::HTTPBadRequest
71
- yield(response.body)
71
+ when Net::HTTPSuccess,
72
+ Net::HTTPBadRequest, # for invalid request
73
+ Net::HTTPRequestTimeOut # for canceled request
74
+ yield(body)
72
75
  else
73
- if response.body.start_with?("[[")
74
- yield(response.body)
76
+ # "[[" is for command_version=1
77
+ # "{" is for command_version=3
78
+ if body.start_with?("[[") or body.start_with?("{")
79
+ yield(body)
75
80
  else
76
- message =
77
- "#{response.code} #{response.message}: #{response.body}"
81
+ message = "#{response.code} #{response.message}: #{body}"
78
82
  raise Error.new(message)
79
83
  end
80
84
  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-2022 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.8"
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,16 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: groonga-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.8
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Haruka Yoshihara
8
8
  - Kouhei Sutou
9
9
  - Kosuke Asami
10
- autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2023-11-07 00:00:00.000000000 Z
12
+ date: 2024-10-16 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: gqtp
@@ -286,7 +285,6 @@ homepage: https://github.com/ranguba/groonga-client
286
285
  licenses:
287
286
  - LGPLv2.1+
288
287
  metadata: {}
289
- post_install_message:
290
288
  rdoc_options: []
291
289
  require_paths:
292
290
  - lib
@@ -301,8 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
301
299
  - !ruby/object:Gem::Version
302
300
  version: '0'
303
301
  requirements: []
304
- rubygems_version: 3.5.0.dev
305
- signing_key:
302
+ rubygems_version: 3.6.0.dev
306
303
  specification_version: 4
307
304
  summary: Groonga-client is a client for Groonga (http://groonga.org/) implemented
308
305
  with pure Ruby. You can use it without Groonga.