reflex-dev/reflex · error · ValueError
rx.match should have at least one case.
Error message
rx.match should have at least one case.
What it means
`rx.match` requires at least one (condition, value) tuple case plus optionally a trailing default. Calling it with an empty argument list after the condition (or where the default consumed the only argument) leaves no cases to evaluate and raises ValueError.
Solutions
- Provide at least one (pattern, value) tuple: rx.match(State.x, ('a', 1), 0)
- When generating cases dynamically, assert non-empty before calling: assert cases, 'need >=1 match case'
- Keep the trailing default after at least one tuple
Example fix
# before
rx.match(State.level, 'none') # no tuple cases
# after
rx.match(State.level, ('high', 3), ('low', 1), 0) Defensive patterns
Strategy: validation
Validate before calling
assert cases, 'rx.match requires at least one (pattern, value) tuple' result = rx.match(State.x, *cases, default)
Prevention
- Never call rx.match without at least one tuple case
- When building cases from data, fall back to a plain value if the list is empty
When it happens
Trigger: `rx.match(State.x)` with no cases; `rx.match(State.x, 'fallback')` where the lone string is consumed as the default, leaving zero tuple cases (this site raises the empty-cases error when tuples list ends up empty).
Common situations: Programmatically building the case list from data that turns out empty; refactoring removes all cases but leaves the call.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- A case tuple should have at least a match case element and…
- For cases with return types as Vars, a default case must be…
- Match cases should have the same return types. Case
- Match children count mismatch: expected
- Match condition of case cannot be a component.
AI-assisted analysis of reflex-dev/reflex@45b8ed5ab7 (2026-08-28).
Data as JSON: /api/errors/ee412d29b4c432be.
Report an issue: GitHub.
Appendix: source
Thrown at packages/reflex-components-core/src/reflex_components_core/core/match.py:102
@classmethod
def _process_cases(
cls, cases: list
) -> tuple[list[tuple], Var | BaseComponent | None]:
"""Process the list of match cases and the catchall default case.
Args:
cases: The list of match cases.
Returns:
The default case and the list of match case tuples.
Raises:
ValueError: If there are multiple default cases.
"""
if not cases:
msg = "rx.match should have at least one case."
raise ValueError(msg)
if not isinstance(cases[-1], tuple):
*cases, default_return = cases
default_return = (
cls._create_case_var_with_var_data(default_return)
if not isinstance(default_return, BaseComponent)
else default_return
)
else:
default_return = None
if any(case for case in cases if not isinstance(case, tuple)):
msg = "rx.match should have tuples of cases and one default case as the last argument."
raise ValueError(msg)
if not cases:
msg = "rx.match should have at least one case."
raise ValueError(msg)View on GitHub (pinned to 45b8ed5ab7)