Add EntityDoesNotExistError, replace cases of Entity as an error, do some easy Resultification#17855
Conversation
|
It looks like your PR is a breaking change, but you didn't provide a migration guide. Could you add some context on what users should update when this change get released in a new version of Bevy? |
EntityDoesNotExistError and start using itEntityDoesNotExistError, replace cases of Entity as an error, do some easy Resultification
| ))?; | ||
| let ecell = cell | ||
| .get_entity(id) | ||
| .map_err(EntityMutableFetchError::EntityDoesNotExist)?; |
There was a problem hiding this comment.
If we impl From<EntityDoesNotExistError> for EntityMutableFetchError, then ? will do the error mapping for us, right? Would that be worth doing?
There was a problem hiding this comment.
I like that impl: I think it's always the correct mapping.
There was a problem hiding this comment.
I had thought it might be better to be explicit about what conversion is happening, but thinking about it again, using From is probably better
|
@JaySpruce I'll merge this once the new conflicts are resolved. |
|
@alice-i-cecile, good to go |
Objective
There's no general error for when an entity doesn't exist, and some methods are going to need one when they get Resultified. The closest thing is
EntityFetchError, but that error has a slightly more specific purpose.Solution
EntityDoesNotExistError.EntityandEntityDoesNotExistDetails.EntityFetchErrorandQueryEntityError:NoSuchEntityvariant to wrapEntityDoesNotExistErrorand renamed the variant toEntityDoesNotExist.EntityFetchErrortoEntityMutableFetchErrorto make its purpose clearer.TryDespawnErrortoEntityDespawnErrorto make it more general.World::inspect_entityto returnResult<[ok], EntityDoesNotExistError>instead of panicking.World::get_entityandWorldEntityFetch::fetch_refto returnResult<[ok], EntityDoesNotExistError>instead ofResult<[ok], Entity>.UnsafeWorldCell::get_entityto returnResult<UnsafeEntityCell, EntityDoesNotExistError>instead ofOption<UnsafeEntityCell>.Migration Guide
World::inspect_entitynow returnsResult<impl Iterator<Item = &ComponentInfo>, EntityDoesNotExistError>instead ofimpl Iterator<Item = &ComponentInfo>.World::get_entitynow returnsEntityDoesNotExistErroras an error instead ofEntity. You can still access the entity's ID through the error'sentityfield.UnsafeWorldCell::get_entitynow returnsResult<UnsafeEntityCell, EntityDoesNotExistError>instead ofOption<UnsafeEntityCell>.