Skip to content

Commit

Permalink
ReadAssetBytesError::Io exposes failing path (bevyengine#10450)
Browse files Browse the repository at this point in the history
# Objective

Addresses #[10438](bevyengine#10438)

The objective was to include the failing path in the error for the user
to see.

## Solution

Add a `path` field to the `ReadAssetBytesError::Io` variant to expose
the failing path in the error message.

## Migration Guide
- The `ReadAssetBytesError::Io` variant now contains two named fields
instead of converting from `std::io::Error`.
    1. `path`: The requested (failing) path (`PathBuf`)
    2. `source`: The source `std::io::Error`

---------

Co-authored-by: Alice Cecile <[email protected]>
  • Loading branch information
2 people authored and Ray Redondo committed Jan 9, 2024
1 parent 02b18d5 commit f32c14d
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use ron::error::SpannedError;
use serde::{Deserialize, Serialize};
use std::{
any::{Any, TypeId},
path::Path,
path::{Path, PathBuf},
};
use thiserror::Error;

Expand Down Expand Up @@ -440,7 +440,13 @@ impl<'a> LoadContext<'a> {
Default::default()
};
let mut bytes = Vec::new();
reader.read_to_end(&mut bytes).await?;
reader
.read_to_end(&mut bytes)
.await
.map_err(|source| ReadAssetBytesError::Io {
path: path.path().to_path_buf(),
source,
})?;
self.loader_dependencies.insert(path.clone_owned(), hash);
Ok(bytes)
}
Expand Down Expand Up @@ -570,8 +576,12 @@ pub enum ReadAssetBytesError {
#[error(transparent)]
MissingProcessedAssetReaderError(#[from] MissingProcessedAssetReaderError),
/// Encountered an I/O error while loading an asset.
#[error("Encountered an io error while loading asset: {0}")]
Io(#[from] std::io::Error),
#[error("Encountered an io error while loading asset at `{path}`: {source}")]
Io {
path: PathBuf,
#[source]
source: std::io::Error,
},
#[error("The LoadContext for this read_asset_bytes call requires hash metadata, but it was not provided. This is likely an internal implementation error.")]
MissingAssetHash,
}

0 comments on commit f32c14d

Please sign in to comment.