diff --git a/lib/type_struct.rb b/lib/type_struct.rb index d77b15c..a8cd00c 100644 --- a/lib/type_struct.rb +++ b/lib/type_struct.rb @@ -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 = [] diff --git a/lib/type_struct_test.rb b/lib/type_struct_test.rb index 6acc253..64962f7 100644 --- a/lib/type_struct_test.rb +++ b/lib/type_struct_test.rb @@ -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