mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-17 00:07:37 +02:00
use try/except to make parser more resilient against unknown error types
This commit is contained in:
@ -35,7 +35,7 @@ Schema:
|
||||
"round_trip_ms_stddev": float,
|
||||
"responses": [
|
||||
{
|
||||
"type": string, # 'reply', 'timeout', etc. See type_map for all options
|
||||
"type": string, # 'reply', 'timeout', 'unparsable_line', etc. See `_error_type.type_map` for all options
|
||||
"timestamp": float,
|
||||
"bytes": integer,
|
||||
"response_ip": string,
|
||||
@ -364,7 +364,7 @@ def _linux_parse(data):
|
||||
|
||||
# normal responses
|
||||
else:
|
||||
|
||||
try:
|
||||
line = line.replace('(', ' ').replace(')', ' ').replace('=', ' ')
|
||||
|
||||
# positions of items depend on whether ipv4/ipv6 and/or ip/hostname is used
|
||||
@ -393,6 +393,10 @@ def _linux_parse(data):
|
||||
'time_ms': line.split()[tms],
|
||||
'duplicate': True if 'DUP!' in line else False
|
||||
}
|
||||
except Exception:
|
||||
response = {
|
||||
'type': 'unparsable_line'
|
||||
}
|
||||
|
||||
ping_responses.append(response)
|
||||
continue
|
||||
@ -542,6 +546,7 @@ def _bsd_parse(data):
|
||||
|
||||
# normal response
|
||||
else:
|
||||
try:
|
||||
line = line.replace(':', ' ').replace('=', ' ')
|
||||
response = {
|
||||
'type': 'reply',
|
||||
@ -551,11 +556,17 @@ def _bsd_parse(data):
|
||||
'ttl': line.split()[7],
|
||||
'time_ms': line.split()[9]
|
||||
}
|
||||
except Exception:
|
||||
response = {
|
||||
'type': 'unparsable_line'
|
||||
}
|
||||
|
||||
ping_responses.append(response)
|
||||
continue
|
||||
|
||||
# ipv6 lines
|
||||
else:
|
||||
try:
|
||||
line = line.replace(',', ' ').replace('=', ' ')
|
||||
response = {
|
||||
'type': 'reply',
|
||||
@ -565,6 +576,11 @@ def _bsd_parse(data):
|
||||
'ttl': line.split()[7],
|
||||
'time_ms': line.split()[9]
|
||||
}
|
||||
except Exception:
|
||||
response = {
|
||||
'type': 'unparsable_line'
|
||||
}
|
||||
|
||||
ping_responses.append(response)
|
||||
continue
|
||||
|
||||
|
Reference in New Issue
Block a user