mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-27 17:33:13 +08:00
Cleaner server error handling
This commit is contained in:
parent
0fc11b5712
commit
0f4bb6e604
@ -39,6 +39,7 @@ sys.path += [
|
||||
]
|
||||
|
||||
from efro.terminal import Clr
|
||||
from efro.error import CleanError
|
||||
from efro.dataclassutils import dataclass_assign, dataclass_validate
|
||||
from bacommon.servermanager import (ServerConfig, StartServerModeCommand)
|
||||
|
||||
@ -56,7 +57,10 @@ class ServerManagerApp:
|
||||
"""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self._config = self._load_config()
|
||||
try:
|
||||
self._config = self._load_config()
|
||||
except Exception as exc:
|
||||
raise CleanError(f'Error loading config: {exc}')
|
||||
self._done = False
|
||||
self._process_commands: List[Union[str, ServerCommand]] = []
|
||||
self._process_commands_lock = Lock()
|
||||
@ -357,4 +361,9 @@ class ServerManagerApp:
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ServerManagerApp().run_interactive()
|
||||
try:
|
||||
ServerManagerApp().run_interactive()
|
||||
except CleanError as clean_exc:
|
||||
# For clean errors, do a simple print and fail; no tracebacks/etc.
|
||||
clean_exc.print()
|
||||
sys.exit(1)
|
||||
|
||||
@ -79,13 +79,6 @@ class ServerConfig:
|
||||
# over a secure ssh connection.
|
||||
enable_telnet: bool = False
|
||||
|
||||
# Port used for telnet.
|
||||
telnet_port: int = 43250
|
||||
|
||||
# This can be None for no password but PLEASE do not expose that to the
|
||||
# world or your machine will likely get owned.
|
||||
telnet_password: Optional[str] = 'changeme'
|
||||
|
||||
# Series length in teams mode (7 == 'best-of-7' series; a team must
|
||||
# get 4 wins)
|
||||
teams_series_length: int = 7
|
||||
|
||||
@ -68,8 +68,8 @@ def dataclass_assign(instance: Any, values: Dict[str, Any]) -> None:
|
||||
fieldsdict = {f.name: f for f in fields}
|
||||
for key, value in values.items():
|
||||
if key not in fieldsdict:
|
||||
raise AttributeError(f"'{type(instance).__name__}' dataclass has"
|
||||
f" no '{key}' field.")
|
||||
raise AttributeError(
|
||||
f"'{type(instance).__name__}' has no '{key}' field")
|
||||
field = fieldsdict[key]
|
||||
|
||||
# We expect to be operating under 'from __future__ import annotations'
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user