Skip to content

Commit 270276d

Browse files
Ihor Dotsenkoshishirmk
authored andcommitted
Fix bug with chaining rescues of FastJsonapi::MultiToJson::Result
1 parent cf86cd8 commit 270276d

2 files changed

Lines changed: 29 additions & 2 deletions

File tree

lib/fast_jsonapi/multi_to_json.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ module MultiToJson
1212
# e.g. https://github.com/github/github-ds/blob/fbda5389711edfb4c10b6c6bad19311dfcb1bac1/lib/github/result.rb
1313
class Result
1414
def initialize(*rescued_exceptions)
15-
rescued_exceptions = [StandardError] if rescued_exceptions.empty?
15+
@rescued_exceptions = if rescued_exceptions.empty?
16+
[StandardError]
17+
else
18+
rescued_exceptions
19+
end
20+
1621
@value = yield
1722
@error = nil
1823
rescue *rescued_exceptions => e
@@ -33,7 +38,8 @@ def value!
3338

3439
def rescue
3540
return self if ok?
36-
Result.new { yield(@error) }
41+
42+
Result.new(*@rescued_exceptions) { yield(@error) }
3743
end
3844
end
3945

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
require 'spec_helper'
2+
3+
module FastJsonapi
4+
module MultiToJson
5+
describe Result do
6+
it 'supports chaining of rescues' do
7+
expect do
8+
Result.new(LoadError) do
9+
require '1'
10+
end.rescue do
11+
require '2'
12+
end.rescue do
13+
require '3'
14+
end.rescue do
15+
'4'
16+
end
17+
end.not_to raise_error
18+
end
19+
end
20+
end
21+
end

0 commit comments

Comments
 (0)