-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't use anyhow
when writing custom AssetLoader
s or AssetSaver
s
#10350
Comments
did you do something like this?
|
@deltanedas Naw I just enumerated the error types since I figured if I'm being made to pull in However it doesn't seem intended that I had to pull in |
i think its an issue on anyhows end since youd expect to be able to use it for something that wants std error trait |
@bushrat011899 any idea what's going on here? It's not clear to me whether this is a trait bound issue or if the migration guide suggesting |
i looked at anyhow and couldnt see any Error trait implemention, bounds or not. |
There's a github issue describing why anyhow::Error doesn't implement std::error::Error: dtolnay/anyhow#25 Looking at the doc, anyhow doesn't implment Error but it has AsRef, Deref, and From implementation (From to StdError) to allow conversion. |
That's a mistake on my part then! When I made that PR, I assumed |
@bushrat011899 I did try the first one before I made the issue, but unfortunately the way the trait bounds are set up it seems to want the boxed type to be
I'm not sure how to get a newtype around |
Unfortunately I think that's exactly correct. I do apologise for my mistake regarding the migration guide for those relying on |
I still think we should try to make the associated Error type able to support anyhow::Error in some way, or enable some sort of generic Error handling. As far as I'm aware there's not really any sort of error handling that is type specific for AssetReader, just using the Error trait. Meanwhile, I have at least 4 different AssetReaders in my code currently across different crates, and now I have to create different error types for different ones and make sure that they convert all the errors to the appropriate type. It might not make it into one of the 0.12.x patches, but supporting anyhow in 0.13 would be ideal |
If you don't care about strong error typing, you can use |
@rlidwka As also mentioned above, that produces an error message currently - the compiler wants the boxed type to be |
@Roryl-c, okay, sounds like a bug then. Do you have a minimal example (of a code that worked with anyhow before) that we can try out? |
this fixes bevyengine#10350 Previous change made in bevyengine#10003 resulted in inability for users to have ?Sized errors, which caused usability issues with crates like anyhow.
this fixes bevyengine#10350 Previous change made in bevyengine#10003 resulted in inability for users to have ?Sized errors, which caused usability issues with crates like anyhow.
I also stepped onto this problem. I wanted to use |
anyhow::Error does not implement std::error::Error but converting to boxed std::error::Error is possible. At the same time this bound should work fine with custom error types like ones generated by thiserror. Note: after this change Bevy 0.12 migration guide claim that anyhow::Error works in this context becomes true. Fixes bevyengine#10350
anyhow::Error does not implement std::error::Error but converting to boxed std::error::Error is possible. At the same time this bound should work fine with custom error types like ones generated by thiserror. Note: after this change Bevy 0.12 migration guide claim that anyhow::Error works in this context becomes true. Fixes bevyengine#10350
#10493) # Objective * In Bevy 0.11 asset loaders used `anyhow::Error` for returning errors. In Bevy 0.12 `AssetLoader` (and `AssetSaver`) have associated `Error` type. Unfortunately it's type bounds does not allow `anyhow::Error` to be used despite migration guide claiming otherwise. This makes migration to 0.12 more challenging. Solve this by changing type bounds for associated `Error` type. * Fix #10350 ## Solution Change associated `Error` type bounds to require `Into<Box<dyn std::error::Error + Send + Sync + 'static>>` to be implemented instead of `std::error::Error + Send + Sync + 'static`. Both `anyhow::Error` and errors generated by `thiserror` seems to be fine with such type bound. --- ## Changelog ### Fixed * Fixed compatibility with `anyhow::Error` in `AssetLoader` and `AssetSaver` associated `Error` type
bevyengine#10493) # Objective * In Bevy 0.11 asset loaders used `anyhow::Error` for returning errors. In Bevy 0.12 `AssetLoader` (and `AssetSaver`) have associated `Error` type. Unfortunately it's type bounds does not allow `anyhow::Error` to be used despite migration guide claiming otherwise. This makes migration to 0.12 more challenging. Solve this by changing type bounds for associated `Error` type. * Fix bevyengine#10350 ## Solution Change associated `Error` type bounds to require `Into<Box<dyn std::error::Error + Send + Sync + 'static>>` to be implemented instead of `std::error::Error + Send + Sync + 'static`. Both `anyhow::Error` and errors generated by `thiserror` seems to be fine with such type bound. --- ## Changelog ### Fixed * Fixed compatibility with `anyhow::Error` in `AssetLoader` and `AssetSaver` associated `Error` type
#10493) # Objective * In Bevy 0.11 asset loaders used `anyhow::Error` for returning errors. In Bevy 0.12 `AssetLoader` (and `AssetSaver`) have associated `Error` type. Unfortunately it's type bounds does not allow `anyhow::Error` to be used despite migration guide claiming otherwise. This makes migration to 0.12 more challenging. Solve this by changing type bounds for associated `Error` type. * Fix #10350 ## Solution Change associated `Error` type bounds to require `Into<Box<dyn std::error::Error + Send + Sync + 'static>>` to be implemented instead of `std::error::Error + Send + Sync + 'static`. Both `anyhow::Error` and errors generated by `thiserror` seems to be fine with such type bound. --- ## Changelog ### Fixed * Fixed compatibility with `anyhow::Error` in `AssetLoader` and `AssetSaver` associated `Error` type
bevyengine#10493) # Objective * In Bevy 0.11 asset loaders used `anyhow::Error` for returning errors. In Bevy 0.12 `AssetLoader` (and `AssetSaver`) have associated `Error` type. Unfortunately it's type bounds does not allow `anyhow::Error` to be used despite migration guide claiming otherwise. This makes migration to 0.12 more challenging. Solve this by changing type bounds for associated `Error` type. * Fix bevyengine#10350 ## Solution Change associated `Error` type bounds to require `Into<Box<dyn std::error::Error + Send + Sync + 'static>>` to be implemented instead of `std::error::Error + Send + Sync + 'static`. Both `anyhow::Error` and errors generated by `thiserror` seems to be fine with such type bound. --- ## Changelog ### Fixed * Fixed compatibility with `anyhow::Error` in `AssetLoader` and `AssetSaver` associated `Error` type
Bevy version
v0.12.0
What you did
Tried to use
anyhow::Error
as the value for the associated typeError
in my implementation of anAssetLoader
, as recommended in #10003.What went wrong
Additional information
#10003 suggests that
anyhow::Error
is intended to be a drop-in replacement here, to make migrations easier. I had to addthiserror
as a project dependency just for this one file.The text was updated successfully, but these errors were encountered: