Closed Athosvk closed 6 months ago
I agree that makes sense to fix! Added it to the 0.2 milestone since its a breaking change.
This was fixed in https://github.com/EmbarkStudios/mirror-mirror/pull/136. Will be released as part of 0.2. Not sure when that'll be but probably not too long 🤞
Problem The
Map::insert
API currently returns anOption<Box<dyn Reflect>>
, but if this returnsNone
it can mean there was no previous value, the key type did not match or the value type did not match. Currently there is no way to tell.Additionally it's currently not possible to infer context of operations not succeeding when using other API functions too. All conversions from
dyn Reflect
toT
may fail, but it's not clear where the fail happens. E.g.All three will return
None
, but all for very different reasons.Potential Solution For
Map::insert
specifically (maybe there's other similar instances that I missed), it would help if it would return something like aResult<Option<Box<&dyn Reflect>>>
so that there is a distinguishment between containing a previous value at that key or failing to convert the input types.Ideally the
Result
would also make use of an error type that has some kind of trail? Maybe adding the "path" as part of the error type would make it easier to spot errors in source paths? E.g.Even if the path aspect isn't done, I think returning a
Result
instead ofOption
where conversions can fail would already help quite a bit.