{"record":{"id":"bcbd328d0169dc13","repo":"reflex-dev/reflex","slug":"a-case-tuple-should-have-at-least-a-match-case-ele","errorCode":null,"errorMessage":"A case tuple should have at least a match case element and a return value.","messagePattern":"A case tuple should have at least a match case element and a return value\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"packages/reflex-components-core/src/reflex_components_core/core/match.py","lineNumber":159,"sourceCode":"        cls, cases: list[tuple]\n    ) -> list[tuple[list[Var], BaseComponent | Var]]:\n        \"\"\"Process the individual match cases.\n\n        Args:\n            cases: The match cases.\n\n        Returns:\n            The processed match cases.\n\n        Raises:\n            ValueError: If the default case is not the last case or the tuple elements are less than 2.\n        \"\"\"\n        match_cases: list[tuple[list[Var], BaseComponent | Var]] = []\n        for case_index, case in enumerate(cases):\n            # There should be at least two elements in a case tuple(a condition and return value)\n            if len(case) < 2:\n                msg = \"A case tuple should have at least a match case element and a return value.\"\n                raise ValueError(msg)\n\n            *conditions, return_value = case\n\n            conditions_vars: list[Var] = []\n            for condition_index, condition in enumerate(conditions):\n                if isinstance(condition, BaseComponent):\n                    msg = f\"Match condition {condition_index} of case {case_index} cannot be a component.\"\n                    raise ValueError(msg)\n                conditions_vars.append(cls._create_case_var_with_var_data(condition))\n\n            return_value = (\n                cls._create_case_var_with_var_data(return_value)\n                if not isinstance(return_value, BaseComponent)\n                else return_value\n            )\n\n            if not isinstance(return_value, (Var, BaseComponent)):\n                msg = \"Return value must be a var or component\"","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/reflex-dev/reflex/blob/45b8ed5ab735f8a56bbb09a42384f030eb0208e7/packages/reflex-components-core/src/reflex_components_core/core/match.py#L141-L177","documentation":"Thrown by rx.match when a case tuple has fewer than two elements. Each case must be a tuple of at least one match condition followed by a return value, e.g. (cond, value) or (cond1, cond2, value).","triggerScenarios":"Calling rx.match(cond, (value_only,), ...) or passing a 1-element tuple (or a bare non-tuple item) as a case. Only the last element of each tuple is the return value; everything before it is treated as conditions, so len(case) < 2 leaves no condition.","commonSituations":"Writing a case as (value,) intending it to be an equality match against the condition var, or accidentally wrapping a value in a trailing comma tuple like (value,).","solutions":["Give each case at least one condition and a return value: rx.match(x, (1, \"one\"), (2, \"two\"), \"default\")","For a single-value fallback, pass it as the final default argument, not as a one-element tuple","Check that you are not passing a generator/string that enumerates into unexpected tuple shapes"],"exampleFix":"# before\nrx.match(State.value, (\"hello\",), \"default\")\n# after\nrx.match(State.value, (\"hello\", \"is hello\"), \"default\")","handlingStrategy":"validation","validationCode":"def valid_case(case):\n    return isinstance(case, tuple) and len(case) >= 2\n\nassert all(valid_case(c) for c in cases), 'each match case needs (condition..., return_value)'","typeGuard":"def is_valid_match_case(case: Any) -> TypeGuard[tuple[Any, ...]]:\n    return isinstance(case, tuple) and len(case) >= 2","tryCatchPattern":null,"preventionTips":["Always write cases as (condition, return_value) pairs","Pass the default as the final positional arg, never a 1-tuple"],"tags":["reflex","match","tuple-validation"],"backgroundTag":"invalid-argument-shape","analyzedSha":"45b8ed5ab735f8a56bbb09a42384f030eb0208e7","analyzedAt":"2026-08-28T19:25:27.644Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}