{"record":{"id":"2508a5a3bb33b4ec","repo":"Textualize/textual","slug":"declarationerror-error-name-error-token-error-me","errorCode":null,"errorMessage":"DeclarationError(error.name, error.token, error.message)","messagePattern":"DeclarationError\\(error\\.name, error\\.token, error\\.message\\)","errorType":"validation","errorClass":"DeclarationError","httpStatus":null,"severity":"error","filePath":"src/textual/css/query.py","lineNumber":433,"sourceCode":"        return app._prune(*self.nodes, parent=self._node)\n\n    def set_styles(\n        self, css: str | None = None, **update_styles\n    ) -> DOMQuery[QueryType]:\n        \"\"\"Set styles on matched nodes.\n\n        Args:\n            css: CSS declarations to parser, or None.\n        \"\"\"\n        _rich_traceback_omit = True\n\n        for node in self:\n            node.set_styles(**update_styles)\n        if css is not None:\n            try:\n                new_styles = parse_declarations(css, read_from=(\"set_styles\", \"\"))\n            except DeclarationError as error:\n                raise DeclarationError(error.name, error.token, error.message) from None\n            for node in self:\n                node._inline_styles.merge(new_styles)\n                node.refresh(layout=True)\n        return self\n\n    def refresh(\n        self, *, repaint: bool = True, layout: bool = False, recompose: bool = False\n    ) -> DOMQuery[QueryType]:\n        \"\"\"Refresh matched nodes.\n\n        Args:\n            repaint: Repaint node(s).\n            layout: Layout node(s).\n            recompose: Recompose node(s).\n\n        Returns:\n            Query for chaining.\n        \"\"\"","sourceCodeStart":415,"sourceCodeEnd":451,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/css/query.py#L415-L451","documentation":"DOMNode.set_styles(css=...) parses the CSS string via parse_declarations; a DeclarationError from parsing is re-raised (detached from its internal cause) with the same name/token/message. So this exception means the inline CSS string you passed to set_styles contains an invalid declaration, not a problem with set_styles itself.","triggerScenarios":"`widget.set_styles(css=\"color: reddd; margin: 5x;\")` — any bad color, unit, or unknown rule; dynamic f-string CSS with a bad interpolated value.","commonSituations":"Programmatically generated CSS strings with unvalidated values; copy-pasted TCSS snippets containing unsupported rules; typos in property names or units.","solutions":["Inspect the re-raised DeclarationError fields (name, token, message) to find the offending declaration and fix the CSS string","Validate generated CSS with parse_declarations during development/tests before calling set_styles","Prefer keyword arguments (set_styles(color=\"red\")) for simple cases to avoid string parsing"],"exampleFix":"# before\nwidget.set_styles(css=\"margin: 5x;\")\n# after\nwidget.set_styles(css=\"margin: 5;\")  # or set_styles(margin=5)","handlingStrategy":"try-catch","validationCode":"from textual.css.parse import parse_declarations\ntry:\n    parse_declarations(css)\n    valid = True\nexcept Exception:\n    valid = False","typeGuard":null,"tryCatchPattern":"from textual.css.stylesheet import DeclarationError\ntry:\n    widget.set_styles(css=css)\nexcept DeclarationError as e:\n    widget.set_styles(color=\"white\")  # safe fallback","preventionTips":["Prefer set_styles kwargs over CSS strings; lint generated CSS in tests"],"tags":["textual","css","set-styles","declaration"],"backgroundTag":"invalid-css-value","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}