Skip to content

Commit 7cad7a4

Browse files
committed
Handle exceptions better
1 parent 451c072 commit 7cad7a4

1 file changed

Lines changed: 26 additions & 29 deletions

File tree

zeroconf.py

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,38 +1069,35 @@ def _set_properties(self, properties):
10691069
def _set_text(self, text):
10701070
"""Sets properties and text given a text field"""
10711071
self.text = text
1072-
try:
1073-
result = {}
1074-
end = len(text)
1075-
index = 0
1076-
strs = []
1077-
while index < end:
1078-
length = indexbytes(text, index)
1079-
index += 1
1080-
strs.append(text[index:index + length])
1081-
index += length
1082-
1083-
for s in strs:
1084-
try:
1085-
key, value = s.split(b'=', 1)
1086-
if value == b'true':
1087-
value = True
1088-
elif value == b'false' or not value:
1089-
value = False
1090-
except Exception as e: # TODO stop catching all Exceptions
1091-
log.exception('Unknown error, possibly benign: %r', e)
1092-
# No equals sign at all
1093-
key = s
1072+
result = {}
1073+
end = len(text)
1074+
index = 0
1075+
strs = []
1076+
while index < end:
1077+
length = indexbytes(text, index)
1078+
index += 1
1079+
strs.append(text[index:index + length])
1080+
index += length
1081+
1082+
for s in strs:
1083+
parts = s.split(b'=', 1)
1084+
try:
1085+
key, value = parts
1086+
except ValueError:
1087+
# No equals sign at all
1088+
key = s
1089+
value = False
1090+
else:
1091+
if value == b'true':
1092+
value = True
1093+
elif value == b'false' or not value:
10941094
value = False
10951095

1096-
# Only update non-existent properties
1097-
if key and result.get(key) is None:
1098-
result[key] = value
1096+
# Only update non-existent properties
1097+
if key and result.get(key) is None:
1098+
result[key] = value
10991099

1100-
self._properties = result
1101-
except Exception as e: # TODO stop catching all Exceptions
1102-
log.exception('Unknown error, possibly benign: %r', e)
1103-
self._properties = None
1100+
self._properties = result
11041101

11051102
def get_name(self):
11061103
"""Name accessor"""

0 commit comments

Comments
 (0)