added name of Var to error message (#2827)
This commit is contained in:
parent
5701a72c8f
commit
2a8d9d1ef4
@ -6,7 +6,7 @@ import inspect
|
|||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from typing import TYPE_CHECKING, Any, List, Union
|
from typing import TYPE_CHECKING, Any, List, Optional, Union
|
||||||
|
|
||||||
from reflex import constants
|
from reflex import constants
|
||||||
from reflex.utils import exceptions, serializers, types
|
from reflex.utils import exceptions, serializers, types
|
||||||
@ -603,11 +603,12 @@ def format_query_params(router_data: dict[str, Any]) -> dict[str, str]:
|
|||||||
return {k.replace("-", "_"): v for k, v in params.items()}
|
return {k.replace("-", "_"): v for k, v in params.items()}
|
||||||
|
|
||||||
|
|
||||||
def format_state(value: Any) -> Any:
|
def format_state(value: Any, key: Optional[str] = None) -> Any:
|
||||||
"""Recursively format values in the given state.
|
"""Recursively format values in the given state.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
value: The state to format.
|
value: The state to format.
|
||||||
|
key: The key associated with the value (optional).
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
The formatted state.
|
The formatted state.
|
||||||
@ -617,7 +618,7 @@ def format_state(value: Any) -> Any:
|
|||||||
"""
|
"""
|
||||||
# Handle dicts.
|
# Handle dicts.
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
return {k: format_state(v) for k, v in value.items()}
|
return {k: format_state(v, k) for k, v in value.items()}
|
||||||
|
|
||||||
# Handle lists, sets, typles.
|
# Handle lists, sets, typles.
|
||||||
if isinstance(value, types.StateIterBases):
|
if isinstance(value, types.StateIterBases):
|
||||||
@ -632,7 +633,14 @@ def format_state(value: Any) -> Any:
|
|||||||
if serialized is not None:
|
if serialized is not None:
|
||||||
return serialized
|
return serialized
|
||||||
|
|
||||||
raise TypeError(f"No JSON serializer found for var {value} of type {type(value)}.")
|
if key is None:
|
||||||
|
raise TypeError(
|
||||||
|
f"No JSON serializer found for var {value} of type {type(value)}."
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
raise TypeError(
|
||||||
|
f"No JSON serializer found for State Var '{key}' of value {value} of type {type(value)}."
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def format_state_name(state_name: str) -> str:
|
def format_state_name(state_name: str) -> str:
|
||||||
|
Loading…
Reference in New Issue
Block a user