{"record":{"id":"4951c15e3fcd1274","repo":"reflex-dev/reflex","slug":"rx-match-should-have-tuples-of-cases-and-one-defau","errorCode":null,"errorMessage":"rx.match should have tuples of cases and one default case as the last argument.","messagePattern":"rx\\.match should have tuples of cases and one default case as the last argument\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-core/src/reflex_components_core/core/match.py","lineNumber":116,"sourceCode":"            ValueError: If there are multiple default cases.\n        \"\"\"\n        if not cases:\n            msg = \"rx.match should have at least one case.\"\n            raise ValueError(msg)\n\n        if not isinstance(cases[-1], tuple):\n            *cases, default_return = cases\n            default_return = (\n                cls._create_case_var_with_var_data(default_return)\n                if not isinstance(default_return, BaseComponent)\n                else default_return\n            )\n        else:\n            default_return = None\n\n        if any(case for case in cases if not isinstance(case, tuple)):\n            msg = \"rx.match should have tuples of cases and one default case as the last argument.\"\n            raise ValueError(msg)\n\n        if not cases:\n            msg = \"rx.match should have at least one case.\"\n            raise ValueError(msg)\n\n        return cases, default_return\n\n    @classmethod\n    def _create_case_var_with_var_data(cls, case_element: Any) -> Var:\n        \"\"\"Convert a case element into a Var.If the case\n        is a Style type, we extract the var data and merge it with the\n        newly created Var.\n\n        Args:\n            case_element: The case element.\n\n        Returns:\n            The case element Var.","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-core/src/reflex_components_core/core/match.py#L98-L134","documentation":"rx.match's grammar is: one or more (condition, value) tuple cases, optionally followed by a single non-tuple default. If any argument other than that trailing default is a non-tuple (bare string, number, component), the structure is ambiguous and ValueError is raised.","triggerScenarios":"`rx.match(State.x, 'a', 'b')` (bare values, no tuples); interleaving a default before tuple cases; passing lists instead of tuples for cases.","commonSituations":"Assuming match works like a chain of rx.cond positional pairs; forgetting the parentheses around each case; passing a default in the middle of the argument list.","solutions":["Wrap each case in a tuple: rx.match(State.x, ('a', 'Alpha'), ('b', 'Beta'), 'other')","Put the default (non-tuple) only as the LAST argument","When building cases from data, emit tuples: [(pattern, value), ...]"],"exampleFix":"# before\nrx.match(State.size, 'small', 'large', 'unknown')\n# after\nrx.match(State.size, ('small', 'S'), ('large', 'L'), 'unknown')","handlingStrategy":"validation","validationCode":"for c in cases:\n    assert isinstance(c, tuple) and len(c) == 2, f'bad case: {c!r}'\nresult = rx.match(State.x, *cases, default)","typeGuard":"def valid_match_args(cases, default) -> bool:\n    return bool(cases) and all(isinstance(c, tuple) and len(c) == 2 for c in cases) and not isinstance(default, tuple)","tryCatchPattern":null,"preventionTips":["Write each case as (pattern, value) with parentheses","Default goes last and only once"],"tags":["reflex","match","argument-structure"],"backgroundTag":"invalid-argument-structure","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}