amethyst / shred

Shared resource dispatcher
Apache License 2.0
234 stars 66 forks source link

Better fetch panic message #182

Closed azriel91 closed 4 years ago

azriel91 commented 4 years ago

Currently when fetching a resource which has not been inserted, the panic message may be difficult for consumers to understand:

Tried to fetch a resource of type "amethyst::ecs::storage::MaskedStorage<project::CustomComponent>", but the resource does not exist.
Try adding the resource by inserting it manually or using the `setup` method.

The following should be more helpful:

Tried to fetch resource of type `MaskedStorage<CustomComponent>`[^1] from the `World`, but the resource does not exist.

You may ensure the resource exists through one of the following methods:

* Inserting it when the world is created: `world.insert(..)`.
* If the resource implements `Default`, include it in a system's `SystemData`, and ensure the system is registered in the dispatcher.
* If the resource does not implement `Default`, insert in the world during `System::setup`.

[^1]: Full type name: `amethyst::ecs::storage::MaskedStorage<project::CustomComponent>`