diff --git a/mesop/runtime/context.py b/mesop/runtime/context.py old mode 100644 new mode 100755 index 3f96bd40..64281717 --- a/mesop/runtime/context.py +++ b/mesop/runtime/context.py @@ -1,4 +1,5 @@ import copy +import logging import threading import types import urllib.parse as urlparse @@ -23,6 +24,8 @@ Handler = Callable[[Any], Generator[None, None, None] | None] +logger = logging.getLogger(__name__) + @dataclass(kw_only=True) class NodeSlot: @@ -109,9 +112,12 @@ class Context: def __init__( self, states: dict[type[Any], object], + *, + debug_mode: bool = False, ) -> None: self._node_tree_state = NodeTreeState() self._states: dict[type[Any], object] = states + self._debug_mode = debug_mode # Previous states is used for performing state diffs. self._previous_states: dict[type[Any], object] = copy.deepcopy(states) self._handlers: dict[str, Handler] = {} @@ -383,6 +389,9 @@ def run_event_handler( else: yield else: - raise MesopException( + error_message = ( f"Unknown handler id: {event.handler_id} from event {event}" ) + if self._debug_mode: + raise MesopDeveloperException(error_message) + logger.warning(error_message) diff --git a/mesop/runtime/runtime.py b/mesop/runtime/runtime.py index 8055ceb4..0769b59a 100644 --- a/mesop/runtime/runtime.py +++ b/mesop/runtime/runtime.py @@ -101,7 +101,9 @@ def create_context(self) -> Context: for state_class in self._state_classes: states[state_class] = state_class() - return Context(states=cast(dict[Any, Any], states)) + return Context( + states=cast(dict[Any, Any], states), debug_mode=self.debug_mode + ) def wait_for_hot_reload(self): # If hot reload is in-progress, the path may not be registered yet because the client reload