1
0
mirror of https://github.com/ARM-software/devlib.git synced 2024-10-05 18:30:50 +01:00

collector/dmesg: Handle non-matching regex

Raise an exception allowing diagnosis when a dmesg line does not match
the regex it is supposed to, rather than the cryptic groups()
AttributeError on None.
This commit is contained in:
Douglas Raillard 2024-06-13 10:42:42 +01:00 committed by Marc Bonnici
parent 3c37bf3de1
commit 3e45a2298e

View File

@ -70,7 +70,7 @@ class KernelLogEntry(object):
def parse_raw_level(line):
match = cls._RAW_LEVEL_REGEX.match(line)
if not match:
raise ValueError('dmesg entry format not recognized: {}'.format(line))
raise ValueError(f'dmesg entry format not recognized: {line}')
level, remainder = match.groups()
levels = DmesgCollector.LOG_LEVELS
# BusyBox dmesg can output numbers that need to wrap around
@ -79,11 +79,15 @@ class KernelLogEntry(object):
def parse_pretty_level(line):
match = cls._PRETTY_LEVEL_REGEX.match(line)
if not match:
raise ValueError(f'dmesg entry pretty format not recognized: {line}')
facility, level, remainder = match.groups()
return facility, level, remainder
def parse_timestamp_msg(line):
match = cls._TIMESTAMP_MSG_REGEX.match(line)
if not match:
raise ValueError(f'dmesg entry timestamp format not recognized: {line}')
timestamp, msg = match.groups()
timestamp = timedelta(seconds=float(timestamp.strip()))
return timestamp, msg