diff options
author | Imbris <2002109+Imberflur@users.noreply.github.com> | 2023-04-28 10:53:46 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-28 16:53:46 +0200 |
commit | 95bfff193494a0cc6ac4bc50b6bd5773a2742aa5 (patch) | |
tree | 9bfd5e14eb9451a0db08fc1b342ee3ed34cd4a12 /zellij-utils | |
parent | 0e379fe15a6de2451d255fdf58152c189d1d9623 (diff) |
fix(errors): add file path context to all IO errors in ConfigError (#2412)
Diffstat (limited to 'zellij-utils')
-rw-r--r-- | zellij-utils/src/input/config.rs | 3 | ||||
-rw-r--r-- | zellij-utils/src/input/layout.rs | 4 | ||||
-rw-r--r-- | zellij-utils/src/kdl/mod.rs | 13 |
3 files changed, 9 insertions, 11 deletions
diff --git a/zellij-utils/src/input/config.rs b/zellij-utils/src/input/config.rs index 8022ea28e..4ad4ef89d 100644 --- a/zellij-utils/src/input/config.rs +++ b/zellij-utils/src/input/config.rs @@ -83,9 +83,6 @@ pub enum ConfigError { KdlDeserializationError(#[from] kdl::KdlError), #[error("KdlDeserialization error: {0}")] KdlError(KdlError), // TODO: consolidate these - // Io error - #[error("IoError: {0}")] - Io(#[from] io::Error), #[error("Config error: {0}")] Std(#[from] Box<dyn std::error::Error>), // Io error with path context diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 713b2775a..b4fcbe2c5 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -730,7 +730,9 @@ impl Layout { let swap_layout_and_path = Layout::swap_layout_and_path(&layout_path); let mut kdl_layout = String::new(); - layout_file.read_to_string(&mut kdl_layout)?; + layout_file + .read_to_string(&mut kdl_layout) + .map_err(|e| ConfigError::IoPath(e, layout_path.into()))?; Ok(( layout_path.as_os_str().to_string_lossy().into(), kdl_layout, diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index 1d488f39d..dceaaf36c 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -10,8 +10,6 @@ use crate::input::theme::{FrameConfig, Theme, Themes, UiConfig}; use crate::setup::{find_default_config_dir, get_layout_dir}; use kdl_layout_parser::KdlLayoutParser; use std::collections::HashMap; -use std::fs::File; -use std::io::Read; use strum::IntoEnumIterator; use miette::NamedSource; @@ -1746,9 +1744,8 @@ impl Themes { pub fn from_path(path_to_theme_file: PathBuf) -> Result<Self, ConfigError> { // String is the theme name - let mut file = File::open(path_to_theme_file.clone())?; - let mut kdl_config = String::new(); - file.read_to_string(&mut kdl_config)?; + let kdl_config = std::fs::read_to_string(&path_to_theme_file) + .map_err(|e| ConfigError::IoPath(e, path_to_theme_file.into()))?; let kdl_config: KdlDocument = kdl_config.parse()?; let kdl_themes = kdl_config.get("themes").ok_or(ConfigError::new_kdl_error( "No theme node found in file".into(), @@ -1761,8 +1758,10 @@ impl Themes { pub fn from_dir(path_to_theme_dir: PathBuf) -> Result<Self, ConfigError> { let mut themes = Themes::default(); - for entry in std::fs::read_dir(path_to_theme_dir)? { - let entry = entry?; + for entry in std::fs::read_dir(&path_to_theme_dir) + .map_err(|e| ConfigError::IoPath(e, path_to_theme_dir.clone()))? + { + let entry = entry.map_err(|e| ConfigError::IoPath(e, path_to_theme_dir.clone()))?; let path = entry.path(); if let Some(extension) = path.extension() { if extension == "kdl" { |