Skip to content

Commit 00cab19

Browse files
committed
Update all exceptions
1 parent a3bdc8d commit 00cab19

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

adafruit_wiznet5k/adafruit_wiznet5k.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def __init__(
188188
# attempt to initialize the module
189189
self._ch_base_msb = 0
190190
if self._w5100_init() != 1:
191-
raise AssertionError("Failed to initialize WIZnet module.")
191+
raise RuntimeError("Failed to initialize WIZnet module.")
192192
# Set MAC address
193193
self.mac_address = mac
194194
self.src_port = 0
@@ -216,7 +216,7 @@ def __init__(
216216
if ret != 0:
217217
self._dhcp_client = None
218218
if ret != 0:
219-
raise AssertionError("Failed to configure DHCP Server!")
219+
raise RuntimeError("Failed to configure DHCP Server!")
220220

221221
def set_dhcp(
222222
self, hostname: Optional[str] = None, response_timeout: float = 30
@@ -275,7 +275,7 @@ def get_host_by_name(self, hostname: str) -> bytes:
275275
if self._debug:
276276
print("* Resolved IP: ", ret)
277277
if ret == -1:
278-
raise AssertionError("Failed to resolve hostname!")
278+
raise RuntimeError("Failed to resolve hostname!")
279279
return ret
280280

281281
@property
@@ -485,7 +485,7 @@ def detect_w5500(self) -> int:
485485
"""
486486
self._chip_type = "w5500"
487487
if self.sw_reset() != 0:
488-
raise AssertionError("Chip not reset properly!")
488+
raise RuntimeError("Chip not reset properly!")
489489
self._write_mr(0x08)
490490
# assert self._read_mr()[0] == 0x08, "Expected 0x08."
491491
if self._read_mr()[0] != 0x08:
@@ -516,7 +516,7 @@ def detect_w5100s(self) -> int:
516516
self._chip_type = "w5100s"
517517
# sw reset
518518
if self.sw_reset() != 0:
519-
raise AssertionError("Chip not reset properly!")
519+
raise RuntimeError("Chip not reset properly!")
520520
if self.read(REG_VERSIONR_W5100S, 0x00)[0] != 0x51:
521521
return -1
522522

@@ -629,7 +629,7 @@ def socket_available(self, socket_num: int, sock_type: int = SNMR_TCP) -> int:
629629
)
630630
)
631631
if socket_num > self.max_sockets:
632-
raise AssertionError("Provided socket exceeds max_sockets.")
632+
raise ValueError("Provided socket exceeds max_sockets.")
633633

634634
res = self._get_rx_rcv_size(socket_num)
635635

@@ -683,7 +683,7 @@ def socket_connect(
683683
defaults to SNMR_TCP.
684684
"""
685685
if not self.link_status:
686-
raise AssertionError("Ethernet cable disconnected!")
686+
raise ConnectionError("Ethernet cable disconnected!")
687687
if self._debug:
688688
print(
689689
"* w5k socket connect, protocol={}, port={}, ip={}".format(
@@ -693,7 +693,7 @@ def socket_connect(
693693
# initialize a socket and set the mode
694694
res = self.socket_open(socket_num, conn_mode=conn_mode)
695695
if res == 1:
696-
raise RuntimeError("Failed to initialize a connection with the socket.")
696+
raise ConnectionError("Failed to initialize a connection with the socket.")
697697

698698
# set socket destination IP and port
699699
self._write_sndipr(socket_num, dest)
@@ -707,7 +707,7 @@ def socket_connect(
707707
if self._debug:
708708
print("SN_SR:", self.socket_status(socket_num)[0])
709709
if self.socket_status(socket_num)[0] == SNSR_SOCK_CLOSED:
710-
raise RuntimeError("Failed to establish connection.")
710+
raise ConnectionError("Failed to establish connection.")
711711
elif conn_mode == SNMR_UDP:
712712
self.udp_datasize[socket_num] = 0
713713
return 1
@@ -752,7 +752,7 @@ def socket_listen(
752752
UDP, defaults to SNMR_TCP.
753753
"""
754754
if not self.link_status:
755-
raise AssertionError("Ethernet cable disconnected!")
755+
raise ConnectionError("Ethernet cable disconnected!")
756756
if self._debug:
757757
print(
758758
"* Listening on port={}, ip={}".format(
@@ -813,7 +813,7 @@ def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
813813
:return int: 1 if the socket was opened, 0 if not.
814814
"""
815815
if not self.link_status:
816-
raise AssertionError("Ethernet cable disconnected!")
816+
raise ConnectionError("Ethernet cable disconnected!")
817817
if self._debug:
818818
print("*** Opening socket %d" % socket_num)
819819
status = self._read_snsr(socket_num)[0]
@@ -846,7 +846,7 @@ def socket_open(self, socket_num: int, conn_mode: int = SNMR_TCP) -> int:
846846
self._write_sncr(socket_num, CMD_SOCK_OPEN)
847847
self._read_sncr(socket_num)
848848
if self._read_snsr((socket_num))[0] not in [0x13, 0x22]:
849-
raise AssertionError("Could not open socket in TCP or UDP mode.")
849+
raise RuntimeError("Could not open socket in TCP or UDP mode.")
850850
return 0
851851
return 1
852852

@@ -888,9 +888,9 @@ def socket_read( # pylint: disable=too-many-branches
888888
"""
889889

890890
if not self.link_status:
891-
raise AssertionError("Ethernet cable disconnected!")
891+
raise ConnectionError("Ethernet cable disconnected!")
892892
if socket_num > self.max_sockets:
893-
raise AssertionError("Provided socket exceeds max_sockets.")
893+
raise ValueError("Provided socket exceeds max_sockets.")
894894

895895
# Check if there is data available on the socket
896896
ret = self._get_rx_rcv_size(socket_num)
@@ -984,7 +984,7 @@ def socket_write(
984984
:return int: The number of bytes written to the buffer.
985985
"""
986986
if not self.link_status:
987-
raise AssertionError("Ethernet cable disconnected!")
987+
raise ConnectionError("Ethernet cable disconnected!")
988988
assert socket_num <= self.max_sockets, "Provided socket exceeds max_sockets."
989989
status = 0
990990
ret = 0

adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def parse_dhcp_response(
275275
# -- Parse Packet, FIXED -- #
276276
# Validate OP
277277
if _BUFF[0] != DHCP_BOOT_REPLY:
278-
raise AssertionError(
278+
raise RuntimeError(
279279
"Malformed Packet - \
280280
DHCP message OP is not expected BOOT Reply."
281281
)

adafruit_wiznet5k/adafruit_wiznet5k_socket.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def getaddrinfo(
101101
:return List[Tuple[int, int, int, str, Tuple[str, int]]]: Address info entries.
102102
"""
103103
if not isinstance(port, int):
104-
raise RuntimeError("Port must be an integer")
104+
raise ValueError("Port must be an integer")
105105
if is_ipv4(host):
106106
return [(AF_INET, socktype, proto, "", (host, port))]
107107
return [(AF_INET, socktype, proto, "", (gethostbyname(host), port))]
@@ -284,7 +284,7 @@ def listen(self, backlog: Optional[int] = None) -> None:
284284
:param Optional[int] backlog: Included for compatibility but ignored.
285285
"""
286286
if self._listen_port is None:
287-
raise AssertionError("Use bind to set the port before listen!")
287+
raise RuntimeError("Use bind to set the port before listen!")
288288
_the_interface.socket_listen(self.socknum, self._listen_port)
289289
self._buffer = b""
290290

@@ -342,7 +342,7 @@ def connect(
342342
to None.
343343
"""
344344
if conntype == 0x03:
345-
raise AssertionError(
345+
raise NotImplementedError(
346346
"Error: SSL/TLS is not currently supported by CircuitPython."
347347
)
348348
host, port = address
@@ -568,7 +568,7 @@ def readline(self) -> bytes:
568568
def disconnect(self) -> None:
569569
"""Disconnect a TCP socket."""
570570
if self._sock_type != SOCK_STREAM:
571-
raise AssertionError("Socket must be a TCP socket.")
571+
raise RuntimeError("Socket must be a TCP socket.")
572572
_the_interface.socket_disconnect(self.socknum)
573573

574574
def close(self) -> None:

0 commit comments

Comments
 (0)