diff --git a/optic/exceptions/BUILD b/optic/exceptions/BUILD new file mode 100644 index 000000000..70bf3c6db --- /dev/null +++ b/optic/exceptions/BUILD @@ -0,0 +1,8 @@ +package( + default_visibility = ["//:optic_internal"], +) + +py_library( + name = "exceptions", + srcs = glob(["*.py"]), +) diff --git a/optic/exceptions/__init__.py b/optic/exceptions/__init__.py new file mode 100644 index 000000000..f1e1828c4 --- /dev/null +++ b/optic/exceptions/__init__.py @@ -0,0 +1,15 @@ +class OpticException(Exception): + pass + + +class OpticUserException(Exception): + def __str__(self): + return f"User Error: {super().__str__()}" + + +class OpticInternalException(Exception): + pass + + +class OpticDeveloperException(Exception): + pass diff --git a/optic/lib/BUILD b/optic/lib/BUILD index 46f642b54..29386403e 100644 --- a/optic/lib/BUILD +++ b/optic/lib/BUILD @@ -6,6 +6,7 @@ py_library( name = "lib", srcs = glob(["*.py"]), deps = [ + "//optic/exceptions", "//optic/state", "//protos:ui_py_proto", ], diff --git a/optic/lib/runtime.py b/optic/lib/runtime.py index debd75f4b..303109529 100644 --- a/optic/lib/runtime.py +++ b/optic/lib/runtime.py @@ -2,8 +2,10 @@ from typing import Any, Callable from .session import Session from optic.state.state import Store +from optic.exceptions import OpticUserException Handler = Callable[[Any, Any], None] +newline = "\n" class Runtime: @@ -24,6 +26,16 @@ def reset_session(self): self._session = Session(Store(deepcopy(self._initial_state), self.get_handler)) def run_path(self, path: str) -> None: + if path not in self._path_fns: + paths = list(self._path_fns.keys()) + paths.sort() + raise OpticUserException( + f"""Accessed path: {path} not registered + +Try one of the following paths: +{newline.join(paths)} + """ + ) self._path_fns[path]() def register_path_fn(self, path: str, fn: Callable[[], None]) -> None: diff --git a/web/src/app/app.ts b/web/src/app/app.ts index 79d634d26..faf810f8a 100644 --- a/web/src/app/app.ts +++ b/web/src/app/app.ts @@ -19,6 +19,7 @@ import { ChannelService, ChannelStatus } from "../services/channel_service"; font-size: 1.5rem; font-weight: 500; padding-bottom: 16px; + white-space: preserve; } .exception-title {