diff --git a/crates/eww/src/config/eww_config.rs b/crates/eww/src/config/eww_config.rs index ac8e559..f945291 100644 --- a/crates/eww/src/config/eww_config.rs +++ b/crates/eww/src/config/eww_config.rs @@ -67,7 +67,13 @@ impl EwwConfig { } pub fn get_window(&self, name: &String) -> Result<&EwwWindowDefinition> { - self.windows.get(name).with_context(|| format!("No window named '{}' exists in config", name)) + self.windows.get(name).with_context(|| { + format!( + "No window named '{}' exists in config.\nThis may also be caused by your config failing to load properly, \ + please check for any other errors in that case.", + name + ) + }) } pub fn get_script_var(&self, name: &VarName) -> Result<&ScriptVarDefinition> { diff --git a/crates/yuck/src/config/widget_definition.rs b/crates/yuck/src/config/widget_definition.rs index 4aaf41b..ffdcfff 100644 --- a/crates/yuck/src/config/widget_definition.rs +++ b/crates/yuck/src/config/widget_definition.rs @@ -10,7 +10,7 @@ use crate::{ from_ast::{FromAst, FromAstElementContent}, }, }; -use eww_shared_util::{AttrName, Span, VarName}; +use eww_shared_util::{AttrName, Span, Spanned, VarName}; use super::widget_use::WidgetUse; #[derive(Debug, PartialEq, Eq, Clone, serde::Serialize)] @@ -33,7 +33,7 @@ impl FromAstElementContent for WidgetDefinition { .note(EXPECTED_WIDGET_DEF_FORMAT)?; let expected_args = expected_args.into_iter().map(|x| x.as_symbol().map(AttrName)).collect::>()?; let widget = iter.expect_any().note(EXPECTED_WIDGET_DEF_FORMAT).and_then(WidgetUse::from_ast)?; - iter.expect_done()?; + iter.expect_done().map_err(|e| FormFormatError::WidgetDefMultipleChildren(e.span()))?; Ok(Self { name, expected_args, widget, span, args_span }) } } diff --git a/crates/yuck/src/error.rs b/crates/yuck/src/error.rs index 76c9972..ca90a50 100644 --- a/crates/yuck/src/error.rs +++ b/crates/yuck/src/error.rs @@ -160,12 +160,16 @@ impl AstResultExt for AstResult { pub enum FormFormatError { #[error("Widget definition missing argument list")] WidgetDefArglistMissing(Span), + + #[error("Widget definition has more than one child widget")] + WidgetDefMultipleChildren(Span), } impl Spanned for FormFormatError { fn span(&self) -> Span { match self { FormFormatError::WidgetDefArglistMissing(span) => *span, + FormFormatError::WidgetDefMultipleChildren(span) => *span, } } } diff --git a/crates/yuck/src/format_diagnostic.rs b/crates/yuck/src/format_diagnostic.rs index 58a192a..ebac4f7 100644 --- a/crates/yuck/src/format_diagnostic.rs +++ b/crates/yuck/src/format_diagnostic.rs @@ -254,7 +254,15 @@ impl ToDiagnostic for FormFormatError { FormFormatError::WidgetDefArglistMissing(span) => gen_diagnostic! { msg = self, label = span => "Insert the argument list (e.g.: `[]`) here", - note = "This list will in the future need to declare all the non-global variables / attributes used in this widget.\nThis is not yet neccessary, but is still considered good style.", + note = "This list will in the future need to declare all the non-global variables / attributes used in this widget.\n\ + This is not yet neccessary, but is still considered good style.", + }, + FormFormatError::WidgetDefMultipleChildren(span) => gen_diagnostic! { + msg = self, + label = span => "Found more than one child element here.", + note = "A widget-definition may only contain one child element.\n\ + To include multiple elements, wrap these elements in a single container widget such as `box`.\n\ + This is necessary as eww can't know how you want these elements to be layed out otherwise." }, } }