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
This commit is contained in:
Telzhaak 2020-08-26 21:08:51 +02:00 committed by GitHub
parent b718a2063d
commit 93040ef9a0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,11 +38,18 @@ where
}
fn load_asset(&self, load_request: &LoadRequest) -> Result<TAsset, AssetLoadError> {
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()),
))),
}
}
}