From 05f9d99409ce4750c4eac7f4396e98adee94d9e8 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Thu, 5 Dec 2024 12:03:44 +0100 Subject: [PATCH] fix: log instead of panic on icon path errors --- Cargo.toml | 1 + src/theme/mod.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4f2eeb2..1cbe970 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,6 +15,7 @@ rust-ini = "0.20.0" thiserror = "1.0.56" once_cell = "1.19.0" xdg = "2.5.2" +tracing = "0.1.41" [dev-dependencies] speculoos = "0.11.0" diff --git a/src/theme/mod.rs b/src/theme/mod.rs index d3adeca..ee793ba 100644 --- a/src/theme/mod.rs +++ b/src/theme/mod.rs @@ -14,8 +14,7 @@ mod paths; type Result = std::result::Result; -pub static THEMES: Lazy>> = - Lazy::new(|| get_all_themes().expect("Failed to get theme paths")); +pub static THEMES: Lazy>> = Lazy::new(|| get_all_themes()); pub struct Theme { pub path: ThemePath, @@ -140,14 +139,21 @@ fn try_build_xmp>(name: &str, path: P) -> Option { } // Iter through the base paths and get all theme directories -pub(super) fn get_all_themes() -> Result>> { +pub(super) fn get_all_themes() -> BTreeMap> { let mut icon_themes = BTreeMap::<_, Vec<_>>::new(); let mut found_indices = BTreeMap::new(); let mut to_revisit = Vec::new(); for theme_base_dir in BASE_PATHS.iter() { - for entry in theme_base_dir.read_dir()? { - let entry = entry?; + let dir_iter = match theme_base_dir.read_dir() { + Ok(dir) => dir, + Err(why) => { + tracing::error!(?why, dir = ?theme_base_dir, "unable to read icon theme directory"); + continue; + } + }; + + for entry in dir_iter.filter_map(std::io::Result::ok) { let name = entry.file_name(); let fallback_index = found_indices.get(&name); if let Some(theme) = Theme::from_path(entry.path(), fallback_index) { @@ -171,7 +177,7 @@ pub(super) fn get_all_themes() -> Result>> { } } - Ok(icon_themes) + icon_themes } impl Theme {