{"record":{"id":"211d03b4276e6534","repo":"reflex-dev/reflex","slug":"color-is-not-a-valid-color","errorCode":null,"errorMessage":"Color is not a valid color.","messagePattern":"Color is not a valid color\\.","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"packages/reflex-base/src/reflex_base/vars/color.py","lineNumber":165,"sourceCode":"            The JSON representation of the var.\n\n        Raises:\n            TypeError: If the color is not a valid color.\n        \"\"\"\n        color, alpha, shade = map(\n            get_python_literal,\n            (self._var_value.color, self._var_value.alpha, self._var_value.shade),\n        )\n        if color is None or alpha is None or shade is None:\n            msg = \"Cannot serialize color that contains non-literal vars.\"\n            raise TypeError(msg)\n        if (\n            not isinstance(color, str)\n            or not isinstance(alpha, bool)\n            or not isinstance(shade, int)\n        ):\n            msg = \"Color is not a valid color.\"\n            raise TypeError(msg)\n        return f\"var(--{color}-{'a' if alpha else ''}{shade})\"\n","sourceCodeStart":147,"sourceCodeEnd":167,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-base/src/reflex_base/vars/color.py#L147-L167","documentation":"After unwrapping color/alpha/shade to literals, json() validates their types: color must be str, alpha must be bool, shade must be int. Wrong types produce a malformed CSS var string, so it raises TypeError.","triggerScenarios":"Passing shade=\"5\" (string), alpha=1 (int instead of bool), or color=123 to rx.color and then serializing it.","commonSituations":"Colors parsed from config files or user input where types are strings; accidental truthy ints for alpha.","solutions":["Coerce inputs: shade=int(shade), color=str(color), alpha=bool(alpha)","Validate external color input against the expected types before calling rx.color"],"exampleFix":"# before\nrx.color(\"grass\", alpha=1, shade=\"5\")\n# after\nrx.color(\"grass\", alpha=True, shade=5)","handlingStrategy":"validation","validationCode":"assert isinstance(color, str) and isinstance(alpha, bool) and isinstance(shade, int), 'invalid color parts'","typeGuard":"def is_valid_color_parts(color, alpha, shade) -> bool:\n    return isinstance(color, str) and isinstance(alpha, bool) and isinstance(shade, int)","tryCatchPattern":null,"preventionTips":["Coerce parsed config values: int(shade), bool(alpha), str(color)","Validate user-supplied color input at the app boundary"],"tags":["reflex","color","type-validation","serialization"],"backgroundTag":"type-validation-failed","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}