diff options
author | Aram Drevekenin <aram@poor.dev> | 2022-10-03 17:47:13 +0200 |
---|---|---|
committer | Aram Drevekenin <aram@poor.dev> | 2022-10-03 17:47:19 +0200 |
commit | 699d058c7995443fea7ecd7ae9ed796bf4b81a18 (patch) | |
tree | 02ecfbaa9cf4001402d41879bbbecc6863567335 | |
parent | 03c13336cbf4a2765594adcda171fb77009c84ea (diff) |
fix(layouts): better errors on unknown nodes
3 files changed, 55 insertions, 12 deletions
diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__error_on_unknown_layout_pane_property.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__error_on_unknown_layout_pane_property.snap index b85656408..573ca75a1 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__error_on_unknown_layout_pane_property.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__error_on_unknown_layout_pane_property.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 903 +assertion_line: 926 expression: "format!(\"{:?}\", layout_error)" --- -KdlError(KdlError { error_message: "Invalid pane property 'spit_size'", src: Some(NamedSource { name: "layout_file_name", source: "<redacted>"), offset: Some(30), len: Some(16) }) +KdlError(KdlError { error_message: "Unknown pane property: spit_size", src: Some(NamedSource { name: "layout_file_name", source: "<redacted>"), offset: Some(35), len: Some(11) }) diff --git a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__error_on_unknown_layout_pane_template_property.snap b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__error_on_unknown_layout_pane_template_property.snap index 404f988cd..09701ebe4 100644 --- a/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__error_on_unknown_layout_pane_template_property.snap +++ b/zellij-utils/src/input/unit/snapshots/zellij_utils__input__layout__layout_test__error_on_unknown_layout_pane_template_property.snap @@ -1,6 +1,6 @@ --- source: zellij-utils/src/input/./unit/layout_test.rs -assertion_line: 914 +assertion_line: 939 expression: "format!(\"{:?}\", layout_error)" --- -KdlError(KdlError { error_message: "Invalid pane property 'spit_size'", src: Some(NamedSource { name: "layout_file_name", source: "<redacted>"), offset: Some(30), len: Some(49) }) +KdlError(KdlError { error_message: "Unknown pane property: spit_size", src: Some(NamedSource { name: "layout_file_name", source: "<redacted>"), offset: Some(68), len: Some(11) }) diff --git a/zellij-utils/src/kdl/kdl_layout_parser.rs b/zellij-utils/src/kdl/kdl_layout_parser.rs index 93e7e8b17..cc2eedc73 100644 --- a/zellij-utils/src/kdl/kdl_layout_parser.rs +++ b/zellij-utils/src/kdl/kdl_layout_parser.rs @@ -67,6 +67,8 @@ impl<'a> KdlLayoutParser<'a> { || property_name == "cwd" || property_name == "args" || property_name == "split_direction" + || property_name == "pane" + || property_name == "children" } fn is_a_valid_tab_property(&self, property_name: &str) -> bool { property_name == "focus" || property_name == "name" || property_name == "split_direction" @@ -362,6 +364,18 @@ impl<'a> KdlLayoutParser<'a> { pane_template, &pane_template_kdl_node, )?); + } else if self.is_a_valid_tab_property(kdl_name!(child)) { + return Err(ConfigError::new_kdl_error( + format!("Tab property '{}' must be placed on the tab title line and not in the child braces", kdl_name!(child)), + child.span().offset(), + child.span().len() + )); + } else { + return Err(ConfigError::new_kdl_error( + format!("Invalid tab property: {}", kdl_name!(child)), + child.span().offset(), + child.span().len() + )); } } if nodes.is_empty() { @@ -389,6 +403,12 @@ impl<'a> KdlLayoutParser<'a> { pane_template, &pane_template_kdl_node, )?); + } else if !self.is_a_valid_pane_property(kdl_name!(child)) { + return Err(ConfigError::new_kdl_error( + format!("Unknown pane property: {}", kdl_name!(child)), + child.span().offset(), + child.span().len(), + )); } } Ok((external_children_index, nodes)) @@ -405,14 +425,25 @@ impl<'a> KdlLayoutParser<'a> { Ok(()) } fn assert_valid_pane_properties(&self, pane_node: &KdlNode) -> Result<(), ConfigError> { - let all_property_names = kdl_property_names!(pane_node); - for name in all_property_names { - if !self.is_a_valid_pane_property(name) { - return Err(ConfigError::new_kdl_error( - format!("Invalid pane property '{}'", name), - pane_node.span().offset(), - pane_node.span().len(), - )); + for entry in pane_node.entries() { + match entry.name().map(|e| e.value()).or_else(|| entry.value().as_string()) { + Some(string_name) => { + if !self.is_a_valid_pane_property(string_name) { + return Err(ConfigError::new_kdl_error( + format!("Unknown pane property: {}", string_name), + entry.span().offset(), + entry.span().len(), + )); + } + }, + None => { + return Err(ConfigError::new_kdl_error( + "Unknown pane property".into(), + entry.span().offset(), + entry.span().len(), + )); + + } } } Ok(()) @@ -530,6 +561,18 @@ impl<'a> KdlLayoutParser<'a> { pane_template, &pane_template_kdl_node, )?); + } else if self.is_a_valid_tab_property(kdl_name!(child)) { + return Err(ConfigError::new_kdl_error( + format!("Tab property '{}' must be placed on the tab_template title line and not in the child braces", kdl_name!(child)), + child.span().offset(), + child.span().len() + )); + } else { + return Err(ConfigError::new_kdl_error( + format!("Invalid tab_template property: {}", kdl_name!(child)), + child.span().offset(), + child.span().len() + )); } } } |