raise VBANCMD error on connection failure.

leave teardown procedures to consumer library. (or context manager)
This commit is contained in:
onyx-and-iris 2022-09-24 07:45:28 +01:00
parent 444f95a9d6
commit 733fab45b4
5 changed files with 9 additions and 10 deletions

View File

@ -1,6 +1,6 @@
[tool.poetry]
name = "vban-cmd"
version = "1.4.3"
version = "1.4.4"
description = "Python interface for the VBAN RT Packet Service (Sendtext)"
authors = ["onyx-and-iris <code@onyxandiris.online>"]
license = "MIT"

View File

@ -1,4 +1,3 @@
from .error import VMCMDErrors
from .iremote import IRemote
from .meta import action_prop

View File

@ -1,4 +1,4 @@
class VMCMDErrors(Exception):
class VBANCMDError(Exception):
"""general errors"""
pass

View File

@ -1,6 +1,5 @@
from functools import partial
from .error import VMCMDErrors
from .util import cache_bool, cache_string

View File

@ -3,6 +3,7 @@ import threading
import time
from typing import Optional
from .error import VBANCMDError
from .packet import HEADER_SIZE, SubscribeHeader, VbanRtPacket, VbanRtPacketHeader
from .util import Socket
@ -26,9 +27,9 @@ class Subscriber(threading.Thread):
self.packet.framecounter = count.to_bytes(4, "little")
time.sleep(10)
except socket.gaierror as e:
print(f"Unable to resolve hostname {self._remote.ip}")
self._remote.socks[Socket.register].close()
raise e
err_msg = f"Unable to resolve hostname {self._remote.ip}"
print(err_msg)
raise VBANCMDError(err_msg)
class Updater(threading.Thread):
@ -80,9 +81,9 @@ class Updater(threading.Thread):
_busLabelUTF8c60=data[932:1412],
)
except TimeoutError as e:
print(f"Unable to establish connection with {self._remote.ip}")
[sock.close() for sock in self._remote.socks]
raise e
err_msg = f"Unable to establish connection with {self._remote.ip}"
print(err_msg)
raise VBANCMDError(err_msg)
def _get_rt(self) -> VbanRtPacket:
"""Attempt to fetch data packet until a valid one found"""