diff options
author | a-kenji <aks.kenji@protonmail.com> | 2021-10-01 21:49:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-01 21:49:47 +0200 |
commit | d667dc2a8707e6154ba3a182244ed8b553f27f06 (patch) | |
tree | 9a8c40310241a4a2d22fd0b4b3c9681b1100599f /zellij-utils/src/input/layout.rs | |
parent | ee7b4a85b01111e1d4985a49d261e8b91c9d7a3b (diff) |
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.
Diffstat (limited to 'zellij-utils/src/input/layout.rs')
-rw-r--r-- | zellij-utils/src/input/layout.rs | 12 |
1 files changed, 11 insertions, 1 deletions
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<LayoutFromYaml> = serde_yaml::from_str(&layout)?; + let layout: Option<LayoutFromYaml> = 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) => { |