bevyengine / bevyengine/bevy

Enable error returning from `FromReflect` trait

Open
#5,967 3 comments 0 reactions 0 assignees View on GitHub
A-Reflection C-Usability D-Trivial
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## 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:

1. Add a new method `try_from_reflect` which does the actual parsing and change `from_reflect` to a default impl which just call `try_from_reflect` and convert `Result` into `Option`;
2. Modify `from_reflect` to return a `Result` instead of `Option`;

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.