mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-06-19 00:17:51 +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,
|
"round_trip_ms_stddev": float,
|
||||||
"responses": [
|
"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,
|
"timestamp": float,
|
||||||
"bytes": integer,
|
"bytes": integer,
|
||||||
"response_ip": string,
|
"response_ip": string,
|
||||||
@ -364,7 +364,7 @@ def _linux_parse(data):
|
|||||||
|
|
||||||
# normal responses
|
# normal responses
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
line = line.replace('(', ' ').replace(')', ' ').replace('=', ' ')
|
line = line.replace('(', ' ').replace(')', ' ').replace('=', ' ')
|
||||||
|
|
||||||
# positions of items depend on whether ipv4/ipv6 and/or ip/hostname is used
|
# 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],
|
'time_ms': line.split()[tms],
|
||||||
'duplicate': True if 'DUP!' in line else False
|
'duplicate': True if 'DUP!' in line else False
|
||||||
}
|
}
|
||||||
|
except Exception:
|
||||||
|
response = {
|
||||||
|
'type': 'unparsable_line'
|
||||||
|
}
|
||||||
|
|
||||||
ping_responses.append(response)
|
ping_responses.append(response)
|
||||||
continue
|
continue
|
||||||
@ -542,6 +546,7 @@ def _bsd_parse(data):
|
|||||||
|
|
||||||
# normal response
|
# normal response
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
line = line.replace(':', ' ').replace('=', ' ')
|
line = line.replace(':', ' ').replace('=', ' ')
|
||||||
response = {
|
response = {
|
||||||
'type': 'reply',
|
'type': 'reply',
|
||||||
@ -551,11 +556,17 @@ def _bsd_parse(data):
|
|||||||
'ttl': line.split()[7],
|
'ttl': line.split()[7],
|
||||||
'time_ms': line.split()[9]
|
'time_ms': line.split()[9]
|
||||||
}
|
}
|
||||||
|
except Exception:
|
||||||
|
response = {
|
||||||
|
'type': 'unparsable_line'
|
||||||
|
}
|
||||||
|
|
||||||
ping_responses.append(response)
|
ping_responses.append(response)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# ipv6 lines
|
# ipv6 lines
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
line = line.replace(',', ' ').replace('=', ' ')
|
line = line.replace(',', ' ').replace('=', ' ')
|
||||||
response = {
|
response = {
|
||||||
'type': 'reply',
|
'type': 'reply',
|
||||||
@ -565,6 +576,11 @@ def _bsd_parse(data):
|
|||||||
'ttl': line.split()[7],
|
'ttl': line.split()[7],
|
||||||
'time_ms': line.split()[9]
|
'time_ms': line.split()[9]
|
||||||
}
|
}
|
||||||
|
except Exception:
|
||||||
|
response = {
|
||||||
|
'type': 'unparsable_line'
|
||||||
|
}
|
||||||
|
|
||||||
ping_responses.append(response)
|
ping_responses.append(response)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user