Enable error returning from `FromReflect` trait
What problem does this solve or what need does it fill?
When dealing with FromReflect implementation other than derive, it's hard to know where the error is, since if you have a big tree of nested dyn Reflect objects, any of them may fail and return None.
What solution would you like?
One of those:
- Add a new method
try_from_reflectwhich does the actual parsing and changefrom_reflectto a default impl which just calltry_from_reflectand convertResultintoOption; - Modify
from_reflectto return aResultinstead ofOption;
I prefer 1, since it doesn't introduce a braking change for those which already uses from_reflect, but will break for any manual FromReflect impl, which I think will be fewer use cases.
What alternative(s) have you considered?
Relying on panic or error messages for any manual FromReflect impl
Additional context
If there is a consensus about this feature, I can impl it
My preference is 2: I think this clearer and more idiomatic. I don't mind the breaking change.
Hi! Would it be acceptable to replace Option with an anyhow::Result or is a standard Result the way to go? In the case of a standard Result, what would the preferred error type be?
Standard result with a custom error type describing the possible failure modes :) I'm not sure one exists yet.
Anyhow's results should not be used in library code as they don't contain enough information on how something failed to be automatically actionable.