retriable 5.0.0 → 5.0.1

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: b1518899ae471b83e7167d0f2dce18e198a5069d30e6f05f04c0754ebd1c3b3a
4
- data.tar.gz: 5fdd9babcd9dcb9dceeec99ce861018fd58435f50a184e62a64fa5142523d235
3
+ metadata.gz: 7ec8418b3d0009ce1ddfd7aa839eab270ae479a2a9498660e9cc0da8fa2541c5
4
+ data.tar.gz: efccc4c3e6e29f5ba12426f1ec39503e9c59a9b606389a2c318606a205bb18b7
5
5
  SHA512:
6
- metadata.gz: af50822074d864951bc299bea96cb52ea5d35cbe7d5b0d079e5e633dec30cce8131a8db30339613562155015ee396a8fc7eb21ea841cf8beb0a826842ce314f0
7
- data.tar.gz: d9dfa3ae45a889ee8326ba5aa7fb119af47302dc087e6c4a6b4033cbe0da9178ea41214b3fd5360f904b72f056ff709b5526c7298c2ff173d115803d88ca661e
6
+ metadata.gz: b7a1f5935366d2b243e508f5da6308ebdd403e61b4d4c9dc05f7f3018c3d93a0bacca1e9a2c9c84a0ebdf0fe685116cd4e3a76bf8dbafeaf6edb25f03a4b31fe
7
+ data.tar.gz: b5bdcef731117fc3c379b65a54e8acfecc9403e188089d269c86f721e6f7bf080f4c2670dc20f15ce09941f69e5ee117a493d593ec94c076c300c86eb02de841
data/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # HEAD
2
2
 
3
+ ## 5.0.1
4
+
5
+ ### Bug fixes
6
+
7
+ - `Retriable.retriable` now propagates `StopIteration` instead of reporting it as
8
+ retry exhaustion. The retry loop used `Kernel#loop`, which rescues
9
+ `StopIteration`, so a block or callback (`on_retry`, `on_give_up`) raising it
10
+ was converted into a `Retriable::ExhaustedError` even when retries remained.
11
+ The loop no longer goes through `Kernel#loop`, so `StopIteration` reaches the
12
+ caller as any other exception would.
13
+ ([#155](https://github.com/kamui/retriable/pull/155))
14
+ - A reused configuration is now validated once, when it is picked up for an
15
+ attempt, instead of being validated again immediately before every use. The
16
+ validation guarantee is unchanged; this only removes the duplicate work on
17
+ each retry.
18
+ ([#156](https://github.com/kamui/retriable/pull/156))
19
+
3
20
  ## 5.0.0
4
21
 
5
22
  **This is a major release with a breaking change. Please read carefully before
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Retriable
4
- VERSION = "5.0.0"
4
+ VERSION = "5.0.1"
5
5
  end
data/lib/retriable.rb CHANGED
@@ -124,14 +124,13 @@ module Retriable
124
124
  def retriable_with_config(base_config, opts = {}, &)
125
125
  override_config = current_override
126
126
  local_config = if opts.empty? && !override_config
127
+ # A reused config may have been mutated inside configure.
128
+ base_config.validate!
127
129
  base_config
128
130
  else
129
131
  Config.new(apply_override_options(merge_layer(base_config.to_h, opts), override_config))
130
132
  end
131
133
 
132
- # Config is mutable through `configure`, so validate again immediately before use.
133
- local_config.validate!
134
-
135
134
  plan = retry_plan(local_config)
136
135
  on = local_config.on
137
136
  retry_if = local_config.retry_if
@@ -158,7 +157,7 @@ module Retriable
158
157
  on:, retry_if:, on_retry:, on_give_up:, elapsed_time:, max_elapsed_time:, sleep_disabled:
159
158
  )
160
159
  try = 0
161
- loop do
160
+ while true # rubocop:disable Style/InfiniteLoop -- Kernel#loop swallows StopIteration.
162
161
  try += 1
163
162
  begin
164
163
  return yield(try)
@@ -133,6 +133,19 @@ describe Retriable do
133
133
  expect(@tries).to eq(3)
134
134
  end
135
135
 
136
+ it "re-raises StopIteration after the configured tries" do
137
+ failure = StopIteration.new("end of input")
138
+
139
+ expect do
140
+ described_class.retriable(tries: 2) do
141
+ increment_tries
142
+ raise failure
143
+ end
144
+ end.to(raise_error { |error| expect(error).to equal(failure) })
145
+
146
+ expect(@tries).to eq(2)
147
+ end
148
+
136
149
  it "makes only 1 try when exception raised is not descendent of StandardError" do
137
150
  expect do
138
151
  described_class.retriable { increment_tries_with_exception(NonStandardError) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: retriable
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Chu