{"record":{"id":"ebed394f3aadc24f","repo":"reflex-dev/reflex","slug":"color-must-be-a-string-or-a-var","errorCode":null,"errorMessage":"Color must be a string or a Var","messagePattern":"Color must be a string or a Var","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-core/src/reflex_components_core/core/colors.py","lineNumber":39,"sourceCode":"\n    Args:\n        color: The color to use.\n        shade: The shade of the color to use.\n        alpha: Whether to use the alpha variant of the color.\n\n    Returns:\n        The color object.\n\n    Raises:\n        ValueError: If the color, shade, or alpha are not valid.\n    \"\"\"\n    if isinstance(color, str):\n        if color not in COLORS and REFLEX_VAR_OPENING_TAG not in color:\n            msg = f\"Color must be one of {COLORS}, received {color}\"\n            raise ValueError(msg)\n    elif not isinstance(color, Var):\n        msg = \"Color must be a string or a Var\"\n        raise ValueError(msg)\n\n    if isinstance(shade, int):\n        if shade < MIN_SHADE_VALUE or shade > MAX_SHADE_VALUE:\n            msg = f\"Shade must be between {MIN_SHADE_VALUE} and {MAX_SHADE_VALUE}\"\n            raise ValueError(msg)\n    elif not isinstance(shade, Var):\n        msg = \"Shade must be an integer or a Var\"\n        raise ValueError(msg)\n\n    if not isinstance(alpha, (bool, Var)):\n        msg = \"Alpha must be a boolean or a Var\"\n        raise ValueError(msg)\n\n    return Color(color, shade, alpha)\n","sourceCodeStart":21,"sourceCodeEnd":54,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-core/src/reflex_components_core/core/colors.py#L21-L54","documentation":"`rx.color()` only accepts a `str` (a palette color name) or a `Var`. Passing any other type (int, list, dict, None, tuple) fails this isinstance check before any color resolution happens.","triggerScenarios":"`rx.color(None)`, `rx.color(7)`, `rx.color(['red'])`, or a value read from untyped config data that isn't a string or Var.","commonSituations":"Passing a shade number as the first argument by mistake; forwarding values from user input or JSON config without converting to str; defaulting a parameter to None and forwarding it into rx.color().","solutions":["Ensure the first argument is a str color name or a Var","If the value may be None, provide a fallback: rx.color(color or 'red')","Convert non-string values to str before calling, if they actually hold a palette name"],"exampleFix":"// before\nrx.color(some_config.get('color'))  # may be None or int\n// after\nrx.color(str(some_config.get('color', 'red')))","handlingStrategy":"type-guard","validationCode":"def safe_color(c, default='red'):\n    if c is None:\n        return default\n    return c if isinstance(c, (str, Var)) else str(c)","typeGuard":"def is_color_arg(c) -> bool:\n    return isinstance(c, (str, Var))","tryCatchPattern":null,"preventionTips":["Type-annotate config fields holding colors as str","Never pass ints/None as the first arg of rx.color"],"tags":["reflex","color","type-error"],"backgroundTag":"invalid-argument-type","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}