Skip to content

Commit 98ffea9

Browse files
authored
Merge pull request #185 from dry-rb/keep-original-error-in-failure
Keep original error in failure object
2 parents 65340c3 + 6f2d264 commit 98ffea9

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

lib/dry/struct/class_interface.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def constructor(constructor = nil, **, &block)
306306
def try(input)
307307
success(self[input])
308308
rescue Error => e
309-
failure_result = failure(input, e.message)
309+
failure_result = failure(input, e)
310310
block_given? ? yield(failure_result) : failure_result
311311
end
312312

spec/shared/struct.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,10 @@ def self.new(attributes)
310310
expect(struct.try(name: "John")).to be_a(Dry::Types::Result::Success)
311311
expect(struct.try(name: 42)).to be_a(Dry::Types::Result::Failure)
312312
end
313+
314+
it "keeps an error instance" do
315+
expect(struct.try(name: 42).error).to be_a(Dry::Struct::Error)
316+
end
313317
end
314318
end
315319
end

0 commit comments

Comments
 (0)