Skip to content

Commit 2106baf

Browse files
Add exception messages (#461)
1 parent b03e7f3 commit 2106baf

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

supriya/contexts/realtime.py

+14-15
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ def _teardown_state(self) -> None:
365365

366366
def _validate_can_request(self) -> None:
367367
if self._boot_status not in (BootStatus.BOOTING, BootStatus.ONLINE):
368-
raise ServerOffline
368+
raise ServerOffline("Server already offline!")
369369
pass # Otherwise always OK to request in RT
370370

371371
def _validate_moment_timestamp(self, seconds: Optional[float]) -> None:
@@ -380,7 +380,7 @@ def send(self, message: Union[SupportsOsc, SequenceABC, str]) -> None:
380380
:param message: The message to send.
381381
"""
382382
if self._boot_status == BootStatus.OFFLINE:
383-
raise ServerOffline
383+
raise ServerOffline("Server already offline!")
384384
osc_protocol: OscProtocol = getattr(self, "_osc_protocol")
385385
osc_protocol.send(message)
386386

@@ -513,7 +513,6 @@ def _lifecycle(self, owned: bool = True) -> None:
513513
self._on_lifecycle_event(ServerLifecycleEvent.BOOTED)
514514
self._boot_future.set_result(True)
515515
except TooManyClients:
516-
print("B")
517516
self._shutdown_future.set_result(ServerShutdownEvent.TOO_MANY_CLIENTS)
518517
# await shutdown future, osc panic, process panic
519518
shutdown = self._shutdown_future.result()
@@ -578,7 +577,7 @@ def _setup_notifications(self) -> None:
578577
if response is None or not isinstance(response, (DoneInfo, FailInfo)):
579578
raise RuntimeError
580579
if isinstance(response, FailInfo):
581-
raise TooManyClients
580+
raise TooManyClients("Too many clients connected already")
582581
if len(response.other) == 1: # supernova doesn't provide a max logins value
583582
self._client_id = int(response.other[0])
584583
self._maximum_logins = self._options.maximum_logins
@@ -602,7 +601,7 @@ def boot(self, *, options: Optional[Options] = None, **kwargs) -> "Server":
602601
:param kwargs: Keyword arguments for options.
603602
"""
604603
if self._boot_status != BootStatus.OFFLINE:
605-
raise ServerOnline
604+
raise ServerOnline("Server already online!")
606605
self._boot_status = BootStatus.BOOTING
607606
self._options = self._get_options(options or self._options, **kwargs)
608607
self._boot_future = concurrent.futures.Future()
@@ -627,7 +626,7 @@ def connect(self, *, options: Optional[Options] = None, **kwargs) -> "Server":
627626
:param kwargs: Keyword arguments for options.
628627
"""
629628
if self._boot_status != BootStatus.OFFLINE:
630-
raise ServerOnline
629+
raise ServerOnline("Server already online!")
631630
self._boot_status = BootStatus.BOOTING
632631
self._options = self._get_options(options or self._options, **kwargs)
633632
self._boot_future = concurrent.futures.Future()
@@ -641,15 +640,15 @@ def connect(self, *, options: Optional[Options] = None, **kwargs) -> "Server":
641640
self._lifecycle_thread.start()
642641
if not (self._boot_future.result()):
643642
if self._shutdown_future.result() == ServerShutdownEvent.TOO_MANY_CLIENTS:
644-
raise TooManyClients
643+
raise TooManyClients("Too many clients connected already")
645644
return self
646645

647646
def disconnect(self) -> "Server":
648647
"""
649648
Disconnect from a running server.
650649
"""
651650
if self._boot_status == BootStatus.OFFLINE:
652-
raise ServerOffline
651+
raise ServerOffline("Server already offline!")
653652
if self._is_owner:
654653
raise OwnedServerShutdown("Cannot disconnect from owned server.")
655654
self._shutdown_future.set_result(ServerShutdownEvent.DISCONNECT)
@@ -988,7 +987,7 @@ def sync(self, sync_id: Optional[int] = None, timeout: float = 1.0) -> "Server":
988987
:param sync_id: The sync ID to wait on.
989988
"""
990989
if self._boot_status not in (BootStatus.BOOTING, BootStatus.ONLINE):
991-
raise ServerOffline
990+
raise ServerOffline("Server already offline!")
992991
Sync(
993992
sync_id=sync_id if sync_id is not None else self._get_next_sync_id()
994993
).communicate(server=self, timeout=timeout)
@@ -1188,7 +1187,7 @@ async def _setup_notifications(self) -> None:
11881187
if response is None or not isinstance(response, (DoneInfo, FailInfo)):
11891188
raise RuntimeError
11901189
if isinstance(response, FailInfo):
1191-
raise TooManyClients
1190+
raise TooManyClients("Too many clients connected already")
11921191
if len(response.other) == 1: # supernova doesn't provide a max logins value
11931192
self._client_id = int(response.other[0])
11941193
self._maximum_logins = self._options.maximum_logins
@@ -1214,7 +1213,7 @@ async def boot(
12141213
:param kwargs: Keyword arguments for options.
12151214
"""
12161215
if self._boot_status != BootStatus.OFFLINE:
1217-
raise ServerOnline
1216+
raise ServerOnline("Server already online!")
12181217
self._boot_status = BootStatus.BOOTING
12191218
self._options = self._get_options(options or self._options, **kwargs)
12201219
loop = asyncio.get_running_loop()
@@ -1237,7 +1236,7 @@ async def connect(
12371236
:param kwargs: Keyword arguments for options.
12381237
"""
12391238
if self._boot_status != BootStatus.OFFLINE:
1240-
raise ServerOnline
1239+
raise ServerOnline("Server already online!")
12411240
self._boot_status = BootStatus.BOOTING
12421241
self._options = self._get_options(options or self._options, **kwargs)
12431242
loop = asyncio.get_running_loop()
@@ -1247,15 +1246,15 @@ async def connect(
12471246
self._lifecycle_task = loop.create_task(self._lifecycle(owned=False))
12481247
if not (await self._boot_future):
12491248
if await self._shutdown_future == ServerShutdownEvent.TOO_MANY_CLIENTS:
1250-
raise TooManyClients
1249+
raise TooManyClients("Too many clients connected already")
12511250
return self
12521251

12531252
async def disconnect(self) -> "AsyncServer":
12541253
"""
12551254
Disconnect from a running server.
12561255
"""
12571256
if self._boot_status == BootStatus.OFFLINE:
1258-
raise ServerOffline
1257+
raise ServerOffline("Server already offline!")
12591258
if self._is_owner:
12601259
raise OwnedServerShutdown("Cannot disconnect from owned server.")
12611260
self._shutdown_future.set_result(ServerShutdownEvent.DISCONNECT)
@@ -1602,7 +1601,7 @@ async def sync(
16021601
:param sync_id: The sync ID to wait on.
16031602
"""
16041603
if self._boot_status not in (BootStatus.BOOTING, BootStatus.ONLINE):
1605-
raise ServerOffline
1604+
raise ServerOffline("Server already offline!")
16061605
await Sync(
16071606
sync_id=sync_id if sync_id is not None else self._get_next_sync_id()
16081607
).communicate_async(server=self, timeout=timeout)

0 commit comments

Comments
 (0)