bevy: Can't use `anyhow` when writing custom `AssetLoader`s or `AssetSaver`s
Bevy version
v0.12.0
What you did
Tried to use anyhow::Error
as the value for the associated type Error
in my implementation of an AssetLoader
, as recommended in #10003.
What went wrong
error[E0277]: the trait bound `anyhow::Error: StdError` is not satisfied
--> src\asset.rs:111:18
|
111 | type Error = anyhow::Error;
| ^^^^^^^^^^^^^ the trait `StdError` is not implemented for `anyhow::Error`
|
note: required by a bound in `bevy::asset::AssetLoader::Error`
--> <snip>\bevy_asset\src\loader.rs:31:17
|
31 | type Error: std::error::Error + Send + Sync + 'static;
| ^^^^^^^^^^^^^^^^^ required by this bound in `AssetLoader::Error`
Additional information
#10003 suggests that anyhow::Error
is intended to be a drop-in replacement here, to make migrations easier. I had to add thiserror
as a project dependency just for this one file.
About this issue
- Original URL
- State: closed
- Created 8 months ago
- Comments: 15 (8 by maintainers)
Commits related to this issue
- return type-erased Errors in AssetLoader::load this fixes https://github.com/bevyengine/bevy/issues/10350 Previous change made in https://github.com/bevyengine/bevy/pull/10003 resulted in inability ... — committed to rlidwka/bevy by rlidwka 8 months ago
- return type-erased Errors in AssetLoader::load this fixes https://github.com/bevyengine/bevy/issues/10350 Previous change made in https://github.com/bevyengine/bevy/pull/10003 resulted in inability ... — committed to rlidwka/bevy by rlidwka 8 months ago
- Make AssetLoader/Saver Error type bounds compatible with anyhow anyhow::Error does not implement std::error::Error but converting to boxed std::error::Error is possible. At the same time this bound s... — committed to rafalh/bevy by rafalh 8 months ago
- Make AssetLoader/Saver Error type bounds compatible with anyhow anyhow::Error does not implement std::error::Error but converting to boxed std::error::Error is possible. At the same time this bound s... — committed to rafalh/bevy by rafalh 8 months ago
- Make AssetLoader/Saver Error type bounds compatible with anyhow::Error (#10493) # Objective * In Bevy 0.11 asset loaders used `anyhow::Error` for returning errors. In Bevy 0.12 `AssetLoader` (and `A... — committed to bevyengine/bevy by rafalh 8 months ago
- Make AssetLoader/Saver Error type bounds compatible with anyhow::Error (#10493) # Objective * In Bevy 0.11 asset loaders used `anyhow::Error` for returning errors. In Bevy 0.12 `AssetLoader` (and `A... — committed to projectharmonia/bevy by rafalh 8 months ago
- Make AssetLoader/Saver Error type bounds compatible with anyhow::Error (#10493) # Objective * In Bevy 0.11 asset loaders used `anyhow::Error` for returning errors. In Bevy 0.12 `AssetLoader` (and `A... — committed to bevyengine/bevy by rafalh 8 months ago
- Make AssetLoader/Saver Error type bounds compatible with anyhow::Error (#10493) # Objective * In Bevy 0.11 asset loaders used `anyhow::Error` for returning errors. In Bevy 0.12 `AssetLoader` (and `A... — committed to rdrpenguin04/bevy by rafalh 8 months ago
There’s a github issue describing why anyhow::Error doesn’t implement std::error::Error: https://github.com/dtolnay/anyhow/issues/25
Looking at the doc, anyhow doesn’t implment Error but it has AsRef, Deref, and From implementation (From<Error> to StdError) to allow conversion.
i think its an issue on anyhows end since youd expect to be able to use it for something that wants std error trait