Error should be thrown when attribute does not exist
tiagofsilva opened this issue · 2 comments
tiagofsilva commented
What we have right now is that #matches ignores non existent field, failing silently. I think this is a real problem as the user could lose some time to find out what is going on, when it's all about a simple typo. It's exemplified in the code below:
begin
raise CustomError.new("blabla", "custom message")
rescue ME.matches(/message/, on: :foo)
rescued = true
Maybe just throwing a custom error would be more appropriate in this case?
gvc commented
I think that failing inside a rescue clause is a bad pattern. One possible workaround for the typo case can be a warning message, but I think it's part of the expected behavior to not match an exception that doesn't have such method.