From d667dc2a8707e6154ba3a182244ed8b553f27f06 Mon Sep 17 00:00:00 2001 From: a-kenji Date: Fri, 1 Oct 2021 21:49:47 +0200 Subject: feat(config): Allow empty config files (#720) Fix #714 Allow empty `config` and `layout` files - Currently empty files are parsed as yaml documents, since they are empty they are invalid yaml files and a deseralization error would follow. Now we ignore the incorrect yaml on an empty document and treat it as an empty yaml document. Eg: ``` ``` and ``` --- ``` Are now treated equally. Alternative: Keep treating the files as `yaml` documents. --- zellij-utils/src/input/layout.rs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'zellij-utils/src/input/layout.rs') diff --git a/zellij-utils/src/input/layout.rs b/zellij-utils/src/input/layout.rs index 033614151..2bbc8cb48 100644 --- a/zellij-utils/src/input/layout.rs +++ b/zellij-utils/src/input/layout.rs @@ -161,7 +161,17 @@ impl LayoutFromYaml { let mut layout = String::new(); layout_file.read_to_string(&mut layout)?; - let layout: Option = serde_yaml::from_str(&layout)?; + let layout: Option = match serde_yaml::from_str(&layout) { + Err(e) => { + // needs direct check, as `[ErrorImpl]` is private + // https://github.com/dtolnay/serde-yaml/issues/121 + if layout.is_empty() { + return Ok(LayoutFromYaml::default()); + } + return Err(ConfigError::Serde(e)); + } + Ok(config) => config, + }; match layout { Some(layout) => { -- cgit v1.2.3