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

Most upvoted comments

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