Skip to content

Commit 330ae91

Browse files
committed
Add error handling for decode errors on incoming data
1 parent 77fc0e8 commit 330ae91

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

rflink/protocol.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,15 @@ def connection_made(self, transport):
4848

4949
def data_received(self, data):
5050
"""Add incoming data to buffer."""
51-
data = data.decode()
52-
log.debug('received data: %s', data.strip())
53-
self.buffer += data
54-
self.handle_lines()
51+
try:
52+
data = data.decode()
53+
except UnicodeDecodeError:
54+
invalid_data = data.decode(errors="replace")
55+
log.warning("Error during decode of data, invalid data: %s", invalid_data)
56+
else:
57+
log.debug('received data: %s', data.strip())
58+
self.buffer += data
59+
self.handle_lines()
5560

5661
def handle_lines(self):
5762
"""Assemble incoming data into per-line packets."""

0 commit comments

Comments
 (0)