{"record":{"id":"9a56d2beaa2c4ffe","repo":"elkowar/eww","slug":"this-widget-can-only-be-used-as-a-child-of-some-co","errorCode":null,"errorMessage":"This widget can only be used as a child of some container widget such as box","messagePattern":"This widget can only be used as a child of some container widget such as box","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/eww/src/widgets/build_widget.rs","lineNumber":60,"sourceCode":"\n// TODO in case of custom widgets, we should add a validation step where\n// warnings for unknown attributes (attributes not expected by the widget) are emitted.\n\n/// Build a [`gtk::Widget`] out of a [`WidgetUse`].\n/// This will set up scopes in the [`ScopeGraph`], register all the listeners there,\n/// and recursively generate all the widgets and child widgets.\npub fn build_gtk_widget(\n    graph: &mut ScopeGraph,\n    widget_defs: Rc<HashMap<String, WidgetDefinition>>,\n    calling_scope: ScopeIndex,\n    widget_use: WidgetUse,\n    custom_widget_invocation: Option<Rc<CustomWidgetInvocation>>,\n) -> Result<gtk::Widget> {\n    match widget_use {\n        WidgetUse::Basic(widget_use) => {\n            build_basic_gtk_widget(graph, widget_defs, calling_scope, widget_use, custom_widget_invocation)\n        }\n        WidgetUse::Loop(_) | WidgetUse::Children(_) => Err(anyhow::anyhow!(DiagError(gen_diagnostic! {\n            msg = \"This widget can only be used as a child of some container widget such as box\",\n            label = widget_use.span(),\n            note = \"Hint: try wrapping this in a `box`\"\n        }))),\n    }\n}\n\nfn build_basic_gtk_widget(\n    graph: &mut ScopeGraph,\n    widget_defs: Rc<HashMap<String, WidgetDefinition>>,\n    calling_scope: ScopeIndex,\n    mut widget_use: BasicWidgetUse,\n    custom_widget_invocation: Option<Rc<CustomWidgetInvocation>>,\n) -> Result<gtk::Widget> {\n    if let Some(custom_widget) = widget_defs.clone().get(&widget_use.name) {\n        let widget_use_attributes = custom_widget\n            .expected_args\n            .iter()","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/elkowar/eww/blob/48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa/crates/eww/src/widgets/build_widget.rs#L42-L78","documentation":"build_gtk_widget constructs the GTK widget tree from the yuck AST. WidgetUse::Loop and WidgetUse::Children nodes are special constructs that only make sense as direct children of container widgets (which expand them); encountered anywhere else, eww raises this diagnostic suggesting wrapping in a box.","triggerScenarios":"Using `(for ...)`/`(loop ...)` or `(children)` (or a custom widget invocation that expands to children) directly where a plain widget is expected — i.e. not inside box/other container whose child-population handles these node types.","commonSituations":"Putting a loop at the top level of a window definition without a container; nesting `children` inside a widget that isn't a container; misuse of custom widget definitions that yield children nodes.","solutions":["Wrap the loop/children node in a `box` (or another container widget)","Move the construct into a container widget's child list","Restructure the custom widget so children are consumed by a container"],"exampleFix":"; before\n(box (for i in {\"1 2 3\"} (label :text i)) (children))\n; children directly under non-container context\n\n; after\n(box\n  (box (for i in {\"1 2 3\"} (label :text i)))\n  (box (children)))","handlingStrategy":"validation","validationCode":"// pre-check node type before building\nlet buildable = !matches!(widget_use, WidgetUse::Loop(_) | WidgetUse::Children(_));\nif !buildable { /* wrap in box first */ }","typeGuard":null,"tryCatchPattern":"match build_gtk_widget(...) {\n    Ok(w) => w,\n    Err(e) => { eprintln!(\"widget build failed: {e:#}\"); gtk::Label::new(Some(\"widget error\")).upcast() }\n}","preventionTips":["Always wrap for/children nodes in a box","Top-level window content should be a container widget","Review custom widget expansions for bare children nodes"],"tags":["eww","yuck","widget-tree","diagnostic"],"backgroundTag":"invalid-argument-value","analyzedSha":"48f5aa8b379adf29da0b0bb9ca04164f65d8bdaa","analyzedAt":"2026-09-08T03:13:26.897Z","contentChangedAt":"2026-09-08T03:13:26.897Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}