{"record":{"id":"f1c5982d8975010b","repo":"Textualize/textual","slug":"declarationerror-name-token-message","errorCode":null,"errorMessage":"DeclarationError(name, token, message)","messagePattern":"DeclarationError\\(name, token, message\\)","errorType":"validation","errorClass":"DeclarationError","httpStatus":null,"severity":"error","filePath":"src/textual/css/_styles_builder.py","lineNumber":106,"sourceCode":"\n\nclass StylesBuilder:\n    \"\"\"\n    The StylesBuilder object takes tokens parsed from the CSS and converts\n    to the appropriate internal types.\n    \"\"\"\n\n    def __init__(self) -> None:\n        self.styles = Styles()\n\n    def __rich_repr__(self) -> rich.repr.Result:\n        yield \"styles\", self.styles\n\n    def __repr__(self) -> str:\n        return \"StylesBuilder()\"\n\n    def error(self, name: str, token: Token, message: str | HelpText) -> NoReturn:\n        raise DeclarationError(name, token, message)\n\n    def add_declaration(self, declaration: Declaration) -> None:\n        if not declaration.name:\n            return\n        rule_name = declaration.name.replace(\"-\", \"_\")\n\n        if not declaration.tokens:\n            self.error(\n                rule_name,\n                declaration.token,\n                f\"Missing property value for '{declaration.name}:'\",\n            )\n\n        process_method = getattr(self, f\"process_{rule_name}\", None)\n\n        if process_method is None:\n            suggested_property_name = self._get_suggested_property_name_for_rule(\n                declaration.name","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/css/_styles_builder.py#L88-L124","documentation":"StylesBuilder.error is the central raiser for DeclarationError while building Styles from parsed CSS declarations. Callers (add_declaration, enum/scalar processors, process_display, process_box_sizing) format a message and token; this method attaches the rule name and source token and raises DeclarationError, which surfaces as a stylesheet error with position info.","triggerScenarios":"Any invalid TCSS declaration that reaches a processor: `display: inline-block;` (process_display), bad scalar units (scalar_error), unknown enum values (_process_enum) or multiple-keyword enums — all funnel through error().","commonSituations":"Errors in .tcss files or CSS strings passed to APP_CSS/push_screen styles; the traceback points here but the real cause is the named rule/token in the DeclarationError fields.","solutions":["Read the DeclarationError's name/token/message fields — they identify the exact rule and CSS token; the StylesBuilder.error frame is just plumbing","Fix the named declaration in the stylesheet or inline CSS string","Run parse_declarations/css parsing separately to validate stylesheet strings during development"],"exampleFix":"# before (in styles.tcss)\n# display: inline-block;\n# after\ndisplay: block;","handlingStrategy":"try-catch","validationCode":"from textual.css.parse import parse_declarations\nparse_declarations(\"display: block; opacity: 0.5;\")  # smoke-test CSS in dev","typeGuard":null,"tryCatchPattern":"from textual.css.stylesheet import DeclarationError\ntry:\n    app.add_css(css_string)\nexcept DeclarationError as e:\n    report(f\"bad rule {e.name} at {e.token}\")","preventionTips":["Parse stylesheets during CI so invalid declarations fail tests, not runtime"],"tags":["textual","css","declaration","stylesheet"],"backgroundTag":"invalid-css-value","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}