Skip to content
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

Don't panic on error when loading assets #1286

Merged
merged 3 commits into from
Jan 23, 2021

Conversation

willcrichton
Copy link
Contributor

Right now, loading an asset that doesn't exist causes the IO task to panic. Instead, we can toss a warning and set the load state to Failed so applications can decide how to handle the failure. As @cart mentioned here, eventually the reason for failing can get broadcast as an event. But this PR is a step towards that.

@@ -295,7 +306,9 @@ impl AssetServer {
self.server
.task_pool
.spawn(async move {
server.load_async(owned_path, force).await.unwrap();
if let Err(err) = server.load_async(owned_path, force).await {
warn!("Asset failed to load: {:?}", err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its probably better to rely on the error's "display" implementation here:

warn!("{}", err);

But that requires some changes to the error in question:

  • rename PathLoader to AssetIo (this was already out of sync. PathLoader was an old name for the AssetIo abstraction)
  • add the actual AssetIo error to the message
    #[error("AssetIo encountered an error: {0:?}")]
    AssetIoError(#[from] AssetIoError),

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And if you're feeling generous, you could update the other error messages in that enum to also include their contents (where relevant).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arg actually maybe including the "Asset failed to load" message is a good idea because the error unfortunately doesn't encapsulate that information.

The current Error impl is shared everywhere, which is nice for code size / error handling ergonomics, but makes cases like this nastier.

Feel free to leave this as-is for now (although renaming PathLoader to AssetIo would be nice 😄 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestions, I updated the error text of AssetServerError and AssetIoError to include the contents and use Display where appropriate. Now, I get a warnings that look like:

Jan 23 11:24:25.658  WARN bevy_asset::asset_server: encountered an error while reading an asset: path not found: /Users/will/Code/crateton/assets/models/monkey/config.json

@willcrichton willcrichton force-pushed the handle-asset-failures branch from 39a8a6e to 22e0c99 Compare January 23, 2021 03:02
@cart
Copy link
Member

cart commented Jan 23, 2021

Love the changes. Thanks!

@cart cart merged commit 3d0c4e3 into bevyengine:master Jan 23, 2021
@willcrichton willcrichton deleted the handle-asset-failures branch January 24, 2021 02:21
rparrett pushed a commit to rparrett/bevy that referenced this pull request Jan 27, 2021
* Don't panic on IO errors
* Better formatting for asset server errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants