diff options
| author | John Shin <51249639+shinhs0506@users.noreply.github.com> | 2023-09-26 18:31:20 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-27 10:31:20 +0900 |
| commit | 9c020757a5eaa2eeb9213c5a816db3b123276fd6 (patch) | |
| tree | dc63821fafc9e1178ef0567644625027e8ee41fd | |
| parent | docs(changelog): fix theme color (diff) | |
| download | sl0ppij-9c020757a5eaa2eeb9213c5a816db3b123276fd6.tar.gz sl0ppij-9c020757a5eaa2eeb9213c5a816db3b123276fd6.tar.xz sl0ppij-9c020757a5eaa2eeb9213c5a816db3b123276fd6.zip | |
fix: display parsing error for kdl files located under the 'themes' directory (#2762)
* fix: display parsing error for kdl files located under the 'themes' directory
* refactor: if-let to match
---------
Co-authored-by: Jae-Heon Ji <atx6419@gmail.com>
| -rw-r--r-- | zellij-utils/src/kdl/mod.rs | 11 | ||||
| -rw-r--r-- | zellij-utils/src/setup.rs | 2 |
2 files changed, 9 insertions, 4 deletions
diff --git a/zellij-utils/src/kdl/mod.rs b/zellij-utils/src/kdl/mod.rs index db72b80d..35bf8940 100644 --- a/zellij-utils/src/kdl/mod.rs +++ b/zellij-utils/src/kdl/mod.rs @@ -1791,7 +1791,7 @@ impl Themes { Ok(themes) } - pub fn from_string(raw_string: String) -> Result<Self, ConfigError> { + pub fn from_string(raw_string: &String) -> Result<Self, ConfigError> { let kdl_config: KdlDocument = raw_string.parse()?; let kdl_themes = kdl_config.get("themes").ok_or(ConfigError::new_kdl_error( "No theme node found in file".into(), @@ -1805,8 +1805,13 @@ impl Themes { pub fn from_path(path_to_theme_file: PathBuf) -> Result<Self, ConfigError> { // String is the theme name let kdl_config = std::fs::read_to_string(&path_to_theme_file) - .map_err(|e| ConfigError::IoPath(e, path_to_theme_file.into()))?; - Themes::from_string(kdl_config) + .map_err(|e| ConfigError::IoPath(e, path_to_theme_file.clone()))?; + Themes::from_string(&kdl_config).map_err(|e| match e { + ConfigError::KdlError(kdl_error) => ConfigError::KdlError( + kdl_error.add_src(path_to_theme_file.display().to_string(), kdl_config), + ), + e => e, + }) } pub fn from_dir(path_to_theme_dir: PathBuf) -> Result<Self, ConfigError> { diff --git a/zellij-utils/src/setup.rs b/zellij-utils/src/setup.rs index 44fed5fa..09009a85 100644 --- a/zellij-utils/src/setup.rs +++ b/zellij-utils/src/setup.rs @@ -68,7 +68,7 @@ fn get_default_themes() -> Themes { let mut themes = Themes::default(); for file in ZELLIJ_DEFAULT_THEMES.files() { if let Some(content) = file.contents_utf8() { - match Themes::from_string(content.to_string()) { + match Themes::from_string(&content.to_string()) { Ok(theme) => themes = themes.merge(theme), Err(_) => {}, } |
