diff --git a/src/themes/color.rs b/src/themes/color.rs index 59328c42a..b4a97cbae 100644 --- a/src/themes/color.rs +++ b/src/themes/color.rs @@ -218,8 +218,7 @@ impl FromStr for Color { Color::Hsva(Hsva::new(h, s / 100., v / 100., (a / 100. * 255.) as u8)) } else if color.starts_with("x:") { let name = color.split_at(2).1; - let hex = super::xresources::get_color(name) - .map_err(|e| Self::Err::new(e))? + let hex = super::xresources::get_color(name)? .ok_or_else(|| { Self::Err::new(format!("color {} not defined in ~/.Xresources", name)) })?; diff --git a/src/themes/xresources.rs b/src/themes/xresources.rs index 878e34021..5968d7101 100644 --- a/src/themes/xresources.rs +++ b/src/themes/xresources.rs @@ -2,6 +2,7 @@ use log::debug; use once_cell::sync::Lazy; use regex::Regex; use std::collections::HashMap; +use crate::errors::Error; #[cfg(not(test))] use std::{env, path::PathBuf}; @@ -22,7 +23,7 @@ use tests::read_xresources; static COLOR_REGEX: Lazy = Lazy::new(|| Regex::new(r"^\s*\*(?[^: ]+)\s*:\s*(?#[a-f0-9]{6}).*$").unwrap()); -static COLORS: Lazy, String>> = +static COLORS: Lazy, Error>> = Lazy::new(|| match read_xresources() { Ok(content) => { debug!(".Xresources content:\n{}", content); @@ -37,11 +38,11 @@ static COLORS: Lazy, String>> = .flatten(), )); } - Err(e) => Err(format!("could not read .Xresources: {}", e)), + Err(e) => Err(Error::new(format!("could not read .Xresources: {}", e))), }); -pub fn get_color(name: &str) -> Result, String> { - Ok(COLORS.as_ref().map(|cmap| cmap.get(name))?) +pub fn get_color(name: &str) -> Result, Error> { + Ok(COLORS.as_ref().map(|cmap| cmap.get(name)).map_err(Clone::clone)?) } #[cfg(test)]