{"record":{"id":"acadaf8c7494e2e9","repo":"Textualize/textual","slug":"failed-to-parse-css-error","errorCode":null,"errorMessage":"failed to parse css; {error}","messagePattern":"failed to parse css; (.+?)","errorType":"exception","errorClass":"StylesheetError","httpStatus":null,"severity":"error","filePath":"src/textual/css/stylesheet.py","lineNumber":283,"sourceCode":"            return self._parse_cache[cache_key]\n        except KeyError:\n            pass\n        try:\n            rules = list(\n                parse(\n                    scope,\n                    css,\n                    read_from,\n                    variable_tokens=self._variable_tokens,\n                    is_default_rules=is_default_rules,\n                    tie_breaker=tie_breaker,\n                )\n            )\n\n        except TokenError:\n            raise\n        except Exception as error:\n            raise StylesheetError(f\"failed to parse css; {error}\") from None\n\n        self._parse_cache[cache_key] = rules\n        return rules\n\n    def read(self, filename: str | PurePath) -> None:\n        \"\"\"Read Textual CSS file.\n\n        Args:\n            filename: Filename of CSS.\n\n        Raises:\n            StylesheetError: If the CSS could not be read.\n            StylesheetParseError: If the CSS is invalid.\n        \"\"\"\n        filename = os.path.expanduser(filename)\n        try:\n            with open(filename, \"rt\", encoding=\"utf-8\") as css_file:\n                css = css_file.read()","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/Textualize/textual/blob/06dbeef4bb70fb718236aa418ed658ef4667a126/src/textual/css/stylesheet.py#L265-L301","documentation":"Stylesheet._parse_rules wraps any unexpected exception raised while parsing CSS rules into StylesheetError('failed to parse css; ...'). TokenError subclasses pass through unchanged; everything else (ValueError, KeyError, TypeError from rule construction) is wrapped here.","triggerScenarios":"Valid-tokenized CSS that still fails rule building — invalid easing function, bad opacity value, invalid text-align, or any value that passes tokenization but fails validation in Styles construction.","commonSituations":"Typos in property values that the tokenizer accepts (e.g. 'easing: bounce-quickly', 'opacity: 150%'), or running CSS written for a newer/older Textual version against an incompatible one.","solutions":["Read the wrapped {error} portion — it names the actual failing value","Check the property value against Textual's supported values (easing names, align values, etc.)","If upgrading Textual, re-check the CSS reference for changed property syntax"],"exampleFix":"/* before */\neasing: smooth-in-out;\n/* after */\neasing: in_out_cubic;","handlingStrategy":"try-catch","validationCode":"from textual.css.stylesheet import Stylesheet\nss = Stylesheet()\nss.add_source(css, read_from=\"check.tcss\")\ntry:\n    ss.parse()\nexcept Exception:\n    raise  # fail fast in CI before shipping CSS","typeGuard":null,"tryCatchPattern":"from textual.css.stylesheet import StylesheetError\ntry:\n    stylesheet.parse()\nexcept StylesheetError as e:\n    report(f\"CSS parse failed: {e}\")","preventionTips":["Parse stylesheets in unit tests to catch bad values early","Read the wrapped {error} text to find the real cause","Keep property values within Textual's documented enums"],"tags":["textual","css","stylesheet","parse"],"backgroundTag":"css-value-parse-error","analyzedSha":"06dbeef4bb70fb718236aa418ed658ef4667a126","analyzedAt":"2026-08-27T02:36:57.214Z","schemaVersion":2},"datasetVersion":"2026-08-27T03:17:27.898Z"}