ksss/type_struct

Invalid exception class and error message when executed in irb

Closed this issue · 2 comments

When a script is executed in irb, and type conversion error happens, TypeStruct raises ArgumentError with an unexpected message.
But TypeStruct::MultiTypeError is expected.

How to reproduce:

$ irb -rtype_struct
irb(main):001:0> c = TypeStruct.new(v: TypeStruct::ArrayOf.new(String))
=> #<Class:0x007fab65881360>
irb(main):002:0> c.new(v: 1)
ArgumentError: different prefix: "" and "/Users/frsyuki"
	from /Users/frsyuki/.rbenv/versions/2.3.0/lib/ruby/2.3.0/pathname.rb:520:in `relative_path_from'
	from /Users/frsyuki/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/type_struct-0.7.3/lib/type_struct/exceptions.rb:20:in `block in build_message'
	from /Users/frsyuki/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/type_struct-0.7.3/lib/type_struct/exceptions.rb:16:in `map'
	from /Users/frsyuki/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/type_struct-0.7.3/lib/type_struct/exceptions.rb:16:in `build_message'
	from /Users/frsyuki/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/type_struct-0.7.3/lib/type_struct/exceptions.rb:10:in `initialize'
	from /Users/frsyuki/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/type_struct-0.7.3/lib/type_struct.rb:32:in `exception'
	from /Users/frsyuki/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/type_struct-0.7.3/lib/type_struct.rb:32:in `raise'
	from /Users/frsyuki/.rbenv/versions/2.3.0/lib/ruby/gems/2.3.0/gems/type_struct-0.7.3/lib/type_struct.rb:32:in `initialize'
	from (irb):2:in `new'
	from (irb):2
	from /Users/frsyuki/.rbenv/versions/2.3.0/bin/irb:11:in `<main>'
ksss commented

@frsyuki Thank you for reporting.
Sorry, I forgot git push 2142cb6

Finally, I've released v0.7.4.
Please check it out!

👍