Warn when computed vars raise an exception (#1939)

This commit is contained in:
Masen Furer 2023-10-17 10:41:36 -07:00 committed by GitHub
parent c3f5f345bb
commit 1efc61e1c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,7 +23,7 @@ from reflex.components.base import (
from reflex.components.component import Component, ComponentStyle, CustomComponent from reflex.components.component import Component, ComponentStyle, CustomComponent
from reflex.state import Cookie, LocalStorage, State from reflex.state import Cookie, LocalStorage, State
from reflex.style import Style from reflex.style import Style
from reflex.utils import format, imports, path_ops from reflex.utils import console, format, imports, path_ops
from reflex.vars import ImportVar from reflex.vars import ImportVar
# To re-export this function. # To re-export this function.
@ -138,7 +138,10 @@ def compile_state(state: Type[State]) -> dict:
""" """
try: try:
initial_state = state().dict() initial_state = state().dict()
except Exception: except Exception as e:
console.warn(
f"Failed to compile initial state with computed vars, excluding them: {e}"
)
initial_state = state().dict(include_computed=False) initial_state = state().dict(include_computed=False)
return format.format_state(initial_state) return format.format_state(initial_state)