noiseless 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f66be9c1d81e3b887f0c0d4485381c4535f087f8365e2581c4c41d89cdba0934
4
- data.tar.gz: 1565bffbcfb554d2b6afcc78ebb1ded79c5c58a8f157b1e25ccd9a449cd2abe2
3
+ metadata.gz: 1a2c76e38f11ce0e3d82ecea5c3644022e1b793613e413f81987063e333da393
4
+ data.tar.gz: 7b862a6892326ed2fff34d3aa087d2cdfeafbc1b007b5f5c6285286d12d26a4f
5
5
  SHA512:
6
- metadata.gz: 4a7e23f4eb136bc6c0dc457dcb6f267e000269aceddd6450264ac489429dda2e20c7b382b32c2ab2a91271faeccee419a5c72530e3781087a9f630e8bd16a15d
7
- data.tar.gz: 605cf0980142cbe65692b9ef8d2a543969578620fa17b35e069a0344ac1a5ca5947781c6d9cf617203408a73e11cd08626c000d046e4a7a9839508919de8d463
6
+ metadata.gz: d25d6a3a8fd986c7f99454f358da6abe29a7c64ee4beddab5925a83c580469625dfc20bf6b19e6ca6af0448ea87093d05275b24ef23d7b4b9b17edc93ceec9a4
7
+ data.tar.gz: 61371d2765af21a3d689931abe71afe4b13942fe4b6c7621115b0d75b1ce0a4d249b28f7ffb40a66e1ab28d5da57f65d3d8814e62372bd13c05c74885cd26507
@@ -1,11 +1,20 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "socket"
4
+ require "timeout"
5
+
3
6
  module Noiseless
4
7
  module Adapters
5
8
  module ExecutionModules
6
9
  # Shared Async::HTTP connection handling for HTTP-based adapters.
7
10
  # Host classes must provide a private +default_port+ method.
8
11
  module HttpTransport
12
+ # Low-level failures the Async::HTTP stack raises when it cannot
13
+ # complete a round-trip with the backend (refused/reset connection,
14
+ # DNS failure, transport timeout). These are wrapped into
15
+ # Noiseless::ConnectionError so callers never have to know which HTTP
16
+ # stack is underneath.
17
+ TRANSPORT_ERRORS = [SystemCallError, SocketError, IOError, Timeout::Error].freeze
9
18
  def initialize(hosts: [], **connection_params)
10
19
  # Ensure we always have at least one host
11
20
  hosts_array = Array(hosts)
@@ -69,6 +78,9 @@ module Noiseless
69
78
  client = @clients[host]
70
79
 
71
80
  yield(client)
81
+ rescue *TRANSPORT_ERRORS => e
82
+ raise Noiseless::ConnectionError,
83
+ "search backend unreachable at #{host} (#{e.class}: #{e.message})"
72
84
  end
73
85
 
74
86
  def default_headers
@@ -54,7 +54,7 @@ module Noiseless
54
54
  return unless should_update_search_index?
55
55
 
56
56
  update_search_index_async if noiseless_new_record? || (respond_to?(:changed?) && changed?)
57
- rescue Net::ProtocolError, JSON::ParserError, Timeout::Error => e
57
+ rescue Noiseless::Error => e
58
58
  handle_search_index_error(e, :update)
59
59
  end
60
60
 
@@ -62,7 +62,7 @@ module Noiseless
62
62
  return unless should_update_search_index?
63
63
 
64
64
  update_search_index_async
65
- rescue Net::ProtocolError, JSON::ParserError, Timeout::Error => e
65
+ rescue Noiseless::Error => e
66
66
  handle_search_index_error(e, :update)
67
67
  end
68
68
 
@@ -70,7 +70,7 @@ module Noiseless
70
70
  return unless should_update_search_index?
71
71
 
72
72
  remove_from_search_index_async
73
- rescue Net::ProtocolError, JSON::ParserError, Timeout::Error => e
73
+ rescue Noiseless::Error => e
74
74
  handle_search_index_error(e, :delete)
75
75
  end
76
76
 
@@ -78,7 +78,7 @@ module Noiseless
78
78
  return unless should_update_search_index?
79
79
 
80
80
  remove_from_search_index_async
81
- rescue Net::ProtocolError, JSON::ParserError, Timeout::Error => e
81
+ rescue Noiseless::Error => e
82
82
  handle_search_index_error(e, :delete)
83
83
  end
84
84
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Noiseless
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
data/lib/noiseless.rb CHANGED
@@ -32,6 +32,14 @@ module Noiseless
32
32
  # (malformed query, missing index, shard failures).
33
33
  class SearchError < RequestError; end
34
34
 
35
+ # Raised when the search backend cannot be reached at all: connection
36
+ # refused, DNS failure, reset socket, or transport timeout. Distinct from
37
+ # RequestError, which means the backend *was* reached and replied with an
38
+ # HTTP error. Wrapping happens at the transport boundary (HttpTransport),
39
+ # so callers rescue Noiseless::Error instead of enumerating socket/system
40
+ # exception classes from whatever HTTP stack the transport happens to use.
41
+ class ConnectionError < Error; end
42
+
35
43
  class Configuration
36
44
  attr_accessor :connections_config, :default_connection, :default_adapter, :config_path
37
45
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: noiseless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Abdelkader Boudih