Skip to content

Commit 588cb59

Browse files
committed
Add the source name to AddSourceError::SourceIsProcessed and RemoveSourceError::SourceIsProcessed.
1 parent 3877f72 commit 588cb59

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

crates/bevy_asset/src/io/source.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,11 @@ impl AssetSources {
633633
.read()
634634
.unwrap_or_else(PoisonError::into_inner);
635635
if *started_lock {
636-
return Err(AddSourceError::SourceIsProcessed);
636+
let AssetSourceId::Name(name) = source.id() else {
637+
// We created this with the AssetSourceId::Name
638+
unreachable!()
639+
};
640+
return Err(AddSourceError::SourceIsProcessed(name));
637641
}
638642
}
639643

@@ -672,7 +676,7 @@ impl AssetSources {
672676
.read()
673677
.unwrap_or_else(PoisonError::into_inner);
674678
if *started_lock {
675-
return Err(RemoveSourceError::SourceIsProcessed);
679+
return Err(RemoveSourceError::SourceIsProcessed(name.clone_owned()));
676680
}
677681
}
678682

@@ -704,8 +708,8 @@ impl AssetSources {
704708
pub enum AddSourceError {
705709
/// The provided asset source requires processing, and processing has already started, where adding is currently unsupported.
706710
// TODO: Remove this once it's supported.
707-
#[error("The provided asset source requires processing, but the asset processor has already started. This is currently unsupported - sources needing to be processed can only be added at startup")]
708-
SourceIsProcessed,
711+
#[error("The provided asset source '{0}' requires processing, but the asset processor has already started. This is currently unsupported - sources needing to be processed can only be added at startup")]
712+
SourceIsProcessed(CowArc<'static, str>),
709713
/// An asset source with the given name already exists.
710714
#[error("Asset Source '{0}' already exists")]
711715
NameInUse(CowArc<'static, str>),
@@ -716,8 +720,8 @@ pub enum AddSourceError {
716720
pub enum RemoveSourceError {
717721
/// The requested asset source requires processing, and processing has already started, where removing is currently unsupported.
718722
// TODO: Remove this once it's supported.
719-
#[error("The asset source being removed requires processing, but the asset processor has already started. This is currently unsupported - sources needing to be processed can only be removed at startup")]
720-
SourceIsProcessed,
723+
#[error("The asset source being removed '{0}' requires processing, but the asset processor has already started. This is currently unsupported - sources needing to be processed can only be removed at startup")]
724+
SourceIsProcessed(CowArc<'static, str>),
721725
/// The requested source is missing, so it cannot be removed.
722726
#[error("Asset Source '{0}' does not exist")]
723727
MissingSource(CowArc<'static, str>),

crates/bevy_asset/src/processor/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,13 +1753,13 @@ fn fails_to_add_or_remove_source_after_processor_starts() {
17531753
// We can't remove the source because it is processed.
17541754
assert_eq!(
17551755
asset_server.remove_source("custom_2"),
1756-
Err(RemoveSourceError::SourceIsProcessed)
1756+
Err(RemoveSourceError::SourceIsProcessed("custom_2".into()))
17571757
);
17581758

17591759
// We can't add a processed source, since the processor has started.
17601760
assert_eq!(
17611761
asset_server.add_source("custom_3", &mut create_processed_source(source_gate).0),
1762-
Err(AddSourceError::SourceIsProcessed)
1762+
Err(AddSourceError::SourceIsProcessed("custom_3".into()))
17631763
);
17641764

17651765
// However we can add unprocessed sources even after the processor has started!

0 commit comments

Comments
 (0)