Skip to content

Commit

Permalink
fix: display parsing error for kdl files located under the 'themes' d…
Browse files Browse the repository at this point in the history
…irectory (#2762)

* fix: display parsing error for kdl files located under the 'themes' directory

* refactor: if-let to match

---------

Co-authored-by: Jae-Heon Ji <[email protected]>
  • Loading branch information
shinhs0506 and jaeheonji authored Sep 27, 2023
1 parent 545ca87 commit 9c02075
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions zellij-utils/src/kdl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion zellij-utils/src/setup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(_) => {},
}
Expand Down

0 comments on commit 9c02075

Please sign in to comment.