{"record":{"id":"e05a027357e360b1","repo":"langchain-ai/deepagents","slug":"themecolors-f-name-must-be-a-7-char-hex-color","errorCode":null,"errorMessage":"ThemeColors.{f.name} must be a 7-char hex color (#RRGGBB), got {val!r}","messagePattern":"ThemeColors\\.(.+?) must be a 7-char hex color \\(#RRGGBB\\), got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/theme.py","lineNumber":333,"sourceCode":"    \"\"\"Base application background.\"\"\"\n\n    surface: str\n    \"\"\"Elevated card / panel background.\"\"\"\n\n    def __post_init__(self) -> None:\n        \"\"\"Validate that every field is a valid hex color.\n\n        Raises:\n            ValueError: If any field is not a 7-character hex color string.\n        \"\"\"\n        for f in fields(self):\n            val = getattr(self, f.name)\n            if not _HEX_RE.match(val):\n                msg = (\n                    f\"ThemeColors.{f.name} must be a 7-char hex color\"\n                    f\" (#RRGGBB), got {val!r}\"\n                )\n                raise ValueError(msg)\n\n    @classmethod\n    def merged(cls, base: ThemeColors, overrides: dict[str, str]) -> ThemeColors:\n        \"\"\"Create a new `ThemeColors` by overlaying overrides onto a base.\n\n        Fields present in `overrides` replace the corresponding base value;\n        missing fields inherit from `base`. This lets users specify only the\n        colors they want to customize.\n\n        Args:\n            base: Fallback color set for any field not in `overrides`.\n            overrides: Field-name to hex-color mapping. Unknown keys are\n                silently ignored.\n\n        Returns:\n            New `ThemeColors` with merged values.\n        \"\"\"\n        valid_names = {f.name for f in fields(cls)}","sourceCodeStart":315,"sourceCodeEnd":351,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/theme.py#L315-L351","documentation":"ThemeColors validates every color field at construction time in __post_init__, enforcing 7-character '#RRGGBB' hex strings via _HEX_RE. Any field set to a malformed value (wrong length, missing '#', named color, 8-char RGBA) raises ValueError immediately so bad themes fail fast instead of rendering broken colors.","triggerScenarios":"Constructing ThemeColors directly (or via ThemeEntry/merged overrides) with a value like 'fff', 'red', '#FFF', 'ff0000', '#GGGGGG' or None for any color field.","commonSituations":"Hand-edited theme TOML/JSON config files, copy-pasted colors from CSS that include alpha channels (#RRGGBBAA), lowercase-or-named colors from design systems, or programmatic theme generation missing fields.","solutions":["Convert the reported value to full 7-char hex with a leading '#', e.g. 'ff0000' -> '#ff0000'.","Strip any alpha suffix from 8-digit hex values before constructing ThemeColors.","Validate all override dicts with _HEX_RE (or the same regex) before passing to ThemeColors.merged.","If loading from config, wrap construction in try/except ValueError and surface the offending field name to the user."],"exampleFix":"// before\nThemeColors(background=\"#fff\", foreground=\"#eee\", accent=\"ff0055\")\n// after\nThemeColors(background=\"#ffffff\", foreground=\"#eeeeee\", accent=\"#ff0055\")","handlingStrategy":"validation","validationCode":"import re\n_HEX_RE = re.compile(r\"^#[0-9a-fA-F]{6}$\")\ndef valid_color(val: str) -> bool:\n    return isinstance(val, str) and bool(_HEX_RE.match(val))\ncolors = {\"background\": \"#ffffff\", \"accent\": \"#ff0055\"}\nassert all(valid_color(v) for v in colors.values()), colors","typeGuard":"def is_hex_color(val: object) -> TypeGuard[str]:\n    return isinstance(val, str) and re.fullmatch(r\"#[0-9a-fA-F]{6}\", val) is not None","tryCatchPattern":"try:\n    theme = ThemeColors(**overrides)\nexcept ValueError as exc:\n    print(f\"bad theme color: {exc}\")","preventionTips":["Normalize colors to lowercase '#rrggbb' at config load time.","Reject 8-digit hex/RGBA and named colors before constructing themes.","Add a unit test covering every theme field with the project regex."],"tags":["validation","config","theme"],"backgroundTag":"invalid-hex-color-format","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}