Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change error class from TypeError to TypeStruct::MultiTypeError on from_hash with other object than Hash #16

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/type_struct.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ def to_h
module ClassMethods
def from_hash(arg)
unless h = Hash.try_convert(arg)
raise TypeError, "no implicit conversion from #{arg} to Hash"
begin
raise TypeError, "no implicit conversion from #{arg} to Hash"
rescue => e
raise TypeStruct::MultiTypeError, [e]
end
end
args = {}
errors = []
Expand Down
4 changes: 2 additions & 2 deletions lib/type_struct_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,11 @@ def test_s_from_hash_with_other_object(t)
o = Object.new
begin
a.from_hash(o)
rescue TypeError => e
rescue TypeStruct::MultiTypeError => e
rescue => e
t.error("Unexpected error #{e.class}")
else
t.error("should raise TypeError")
t.error("should raise MultiTypeError")
end

def o.to_hash
Expand Down