From ecc4743fdec43eb578e9c35bb008c68909f1517e Mon Sep 17 00:00:00 2001 From: fxqnlr Date: Wed, 4 Sep 2024 17:32:19 +0200 Subject: better error handling --- src/cache.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/cache.rs') diff --git a/src/cache.rs b/src/cache.rs index 6ffeb52..199a440 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -3,15 +3,15 @@ use std::{ fs::{copy, read_dir}, }; -use crate::error::{EType, MLErr, MLE}; +use crate::errors::{ConversionError, Error, MLE}; /// # Errors pub fn get_cached_versions(path: &str) -> MLE> { let mut versions: HashMap = HashMap::new(); - for file in read_dir(path).map_err(|_| MLErr::new(EType::IoError, "readdir"))? { - let path = file.map_err(|_| MLErr::new(EType::IoError, "file"))?.path(); - if path.is_file() && path.extension().ok_or(MLErr::new(EType::IoError, "ext"))? == "jar" { - let pathstr = path.to_str().ok_or(MLErr::new(EType::IoError, "path"))?; + for file in read_dir(path)? { + let path = file?.path(); + if path.is_file() && path.extension().ok_or(Error::NoFileExtension)? == "jar" { + let pathstr = path.to_str().ok_or(ConversionError::InvalidPath)?; let namesplit: Vec<&str> = pathstr.split('.').collect(); versions.insert( String::from(namesplit[namesplit.len() - 2]), @@ -27,6 +27,6 @@ pub fn copy_cached_version(version_path: &str, download_path: &str) -> MLE<()> { let versplit: Vec<&str> = version_path.split('/').collect(); let download = format!("{}/{}", download_path, versplit[versplit.len() - 1]); - copy(version_path, download).map_err(|err| MLErr::new(EType::IoError, &err.to_string()))?; + copy(version_path, download)?; Ok(()) } -- cgit v1.2.3