From 93040ef9a0f536f3866b75c59363eb13fe27e38b Mon Sep 17 00:00:00 2001 From: Telzhaak Date: Wed, 26 Aug 2020 21:08:51 +0200 Subject: [PATCH] Check asset-path existence. Previously App just crashed if not (#345) * Check asset-path existence. Previously App just crashed if not * rustfmt * Relegated Error-message to ChannelAssetHandler * Removed needless return statement --- crates/bevy_asset/src/load_request.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/bevy_asset/src/load_request.rs b/crates/bevy_asset/src/load_request.rs index 3da04fd952275..462181bf606bc 100644 --- a/crates/bevy_asset/src/load_request.rs +++ b/crates/bevy_asset/src/load_request.rs @@ -38,11 +38,18 @@ where } fn load_asset(&self, load_request: &LoadRequest) -> Result { - let mut file = File::open(&load_request.path)?; - let mut bytes = Vec::new(); - file.read_to_end(&mut bytes)?; - let asset = self.loader.from_bytes(&load_request.path, bytes)?; - Ok(asset) + match File::open(&load_request.path) { + Ok(mut file) => { + let mut bytes = Vec::new(); + file.read_to_end(&mut bytes)?; + let asset = self.loader.from_bytes(&load_request.path, bytes)?; + Ok(asset) + } + Err(e) => Err(AssetLoadError::Io(std::io::Error::new( + e.kind(), + format!("{}", load_request.path.display()), + ))), + } } }