Skip to content

Commit

Permalink
Merge pull request #74 from lowdef/issue72_robustness_fix
Browse files Browse the repository at this point in the history
catch parse errors in TelegramParser, ignore lines that can not be parsed
  • Loading branch information
ndokter authored Feb 7, 2021
2 parents 3dc77a8 + 1cdda2e commit a255380
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions dsmr_parser/parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class TelegramParser(object):

crc16_tab = []

def __init__(self, telegram_specification, apply_checksum_validation=True):
Expand Down Expand Up @@ -56,7 +55,11 @@ def parse(self, telegram_data):
# Some signatures are optional and may not be present,
# so only parse lines that match
if match:
telegram[signature] = parser.parse(match.group(0))
try:
telegram[signature] = parser.parse(match.group(0))
except Exception:
logger.error("ignore line with signature {}, because parsing failed.".format(signature),
exc_info=True)

return telegram

Expand Down Expand Up @@ -219,6 +222,7 @@ class ProfileGenericParser(DSMRObjectParser):
8) Buffer value 2 (oldest entry of buffer attribute without unit)
9) Unit of buffer values (Unit of capture objects attribute)
"""

def __init__(self, buffer_types, head_parsers, parsers_for_unidentified):
self.value_formats = head_parsers
self.buffer_types = buffer_types
Expand Down Expand Up @@ -271,7 +275,6 @@ def __init__(self, coerce_type):
self.coerce_type = coerce_type

def parse(self, value):

unit_of_measurement = None

if value and '*' in value:
Expand Down

0 comments on commit a255380

Please sign in to comment.