Skip to content

Commit 0fd0453

Browse files
committed
🥅 Catch config not found exception in user API
1 parent 958cb59 commit 0fd0453

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

‎simvue/config/user.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import toml
1717
import semver
1818

19+
from simvue.exception import SimvueUserConfigError
1920
import simvue.utilities as sv_util
2021
from simvue.config.parameters import (
2122
ClientGeneralOptions,
@@ -221,10 +222,10 @@ def fetch(
221222
_run_mode = mode or _config_dict["run"].get("mode") or "online"
222223

223224
if not _server_url and _run_mode != "offline":
224-
raise RuntimeError("No server URL was specified")
225+
raise SimvueUserConfigError("No server URL was specified")
225226

226227
if not _server_token and _run_mode != "offline":
227-
raise RuntimeError("No server token was specified")
228+
raise SimvueUserConfigError("No server token was specified")
228229

229230
_config_dict["server"]["token"] = _server_token
230231
_config_dict["server"]["url"] = _server_url

‎simvue/exception.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@ class SimvueRunError(RuntimeError):
2222
"""A special sub-class of runtime error specifically for Simvue run errors"""
2323

2424
pass
25+
26+
27+
class SimvueUserConfigError(Exception):
28+
"""Raised when no local Simvue Configuration file has been found."""
29+
30+
pass

‎simvue/run.py‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from simvue.api.objects.alert.fetch import Alert
3434
from simvue.api.objects.folder import Folder
3535
from simvue.api.objects.grids import GridMetrics
36-
from simvue.exception import ObjectNotFoundError, SimvueRunError
36+
from simvue.exception import ObjectNotFoundError, SimvueRunError, SimvueUserConfigError
3737
from simvue.utilities import prettify_pydantic
3838

3939

@@ -184,9 +184,14 @@ def __init__(
184184
self._data: dict[str, typing.Any] = {}
185185
self._step: int = 0
186186
self._active: bool = False
187-
self._user_config: SimvueConfiguration = SimvueConfiguration.fetch(
188-
server_url=server_url, server_token=server_token, mode=mode
189-
)
187+
188+
try:
189+
self._user_config: SimvueConfiguration = SimvueConfiguration.fetch(
190+
server_url=server_url, server_token=server_token, mode=mode
191+
)
192+
except SimvueUserConfigError as e:
193+
click.secho(f"[simvue] {e}", bold=True, fg="red")
194+
sys.exit(1)
190195

191196
logging.getLogger(self.__class__.__module__).setLevel(
192197
logging.DEBUG

0 commit comments

Comments
 (0)