Swallow exceptions when getting property values during validation#55
Swallow exceptions when getting property values during validation#55DamianEdwards wants to merge 2 commits intomainfrom
Conversation
It's impossible to know if a given property getter will throw during validation due to the state of the object, so just swallow any exception from getting the value. Fixes #54
| try | ||
| { | ||
| propertyValue = property.GetValue(target); | ||
| } | ||
| catch (Exception) { } | ||
| var propertyValueType = propertyValue?.GetType(); |
There was a problem hiding this comment.
I don't think so? Certainly the bug report indicates they want the validation to continue, the issue is that for anything that has a getter that throws when in certain state, the walk will cause it to throw. I still feel like I'm missing something here. I might have to try out this scenario in MVC and step through what it does.
There was a problem hiding this comment.
Should be an opt in. I think blindly swallowing exceptions is bad. Maybe instead have a way to skip a property? (attribute?)
There was a problem hiding this comment.
Already have a way to opt-out of recursing at the property level: https://github.com/DamianEdwards/MiniValidation/blob/main/src/MiniValidation/SkipRecursionAttribute.cs
There was a problem hiding this comment.
What about adding an ValidationResult stating that a certain value could not be retrieved?
It's impossible to know if a given property getter will throw during validation due to the state of the object, so just swallow any exception from getting the value.
Fixes #54