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

Better error message on incorrect asset label #11254

Merged
merged 1 commit into from
Jan 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion crates/bevy_asset/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,16 @@ impl AssetServer {
match loaded_asset.labeled_assets.get(&label) {
Some(labeled_asset) => labeled_asset.handle.clone(),
None => {
let mut all_labels: Vec<String> = loaded_asset
.labeled_assets
.keys()
.map(|s| (**s).to_owned())
.collect();
all_labels.sort_unstable();
return Err(AssetLoadError::MissingLabel {
base_path,
label: label.to_string(),
all_labels,
});
}
}
Expand Down Expand Up @@ -1138,10 +1145,15 @@ pub enum AssetLoadError {
loader_name: &'static str,
error: Box<dyn std::error::Error + Send + Sync + 'static>,
},
#[error("The file at '{base_path}' does not contain the labeled asset '{label}'.")]
#[error("The file at '{}' does not contain the labeled asset '{}'; it contains the following {} assets: {}",
base_path,
label,
all_labels.len(),
all_labels.iter().map(|l| format!("'{}'", l)).collect::<Vec<_>>().join(", "))]
MissingLabel {
base_path: AssetPath<'static>,
label: String,
all_labels: Vec<String>,
},
}

Expand Down