Improve error handling on signature mismatch cases

and cleanup old todos that have been addressed
This commit is contained in:
Kristen Newbury
2022-11-23 14:06:23 -05:00
parent 01b248a2a9
commit 2bda917a4e
3 changed files with 12 additions and 20 deletions

View File

@@ -126,7 +126,7 @@ def joins_for_scans(basetables, external_info, scantables):
"id" : e.scan_id,
"commit_id" : b.project.revisionId[0],
"project_id" : e.project_id,
# TODO extract real date information from somewhere
# TODO extract real date information from somewhere external
"db_create_start" : pd.Timestamp(0.0, unit='s'),
"db_create_stop" : pd.Timestamp(0.0, unit='s'),
"scan_start_date" : pd.Timestamp(0.0, unit='s'),
@@ -165,7 +165,6 @@ def joins_for_results(basetables, external_info):
res = pd.concat(stack)
else:
if stack == []:
# TODO knewbury to error handling
logging.warning("Zero problem/path_problem results found in sarif "
"file but processing anyway.")
status_writer.csv_write(status_writer.zero_results)

View File

@@ -113,7 +113,8 @@ def destructure(typegraph: Typegraph, node: NodeId, tree: Tree):
elif t in [str, int, bool]:
pass
else:
# TODO knewbury error handling
status_writer.unknown_sarif_parsing_shape["extra_info"] = "Unhandled type: %s" % t
status_writer.csv_write(status_writer.unknown_sarif_parsing_shape)
raise Exception("Unhandled type: %s" % t)
def _destructure_dict_1(typegraph, node, tree):
@@ -139,7 +140,7 @@ def _destructure_dict_1(typegraph, node, tree):
# Sanity check
sig = typegraph.signature_graph[node]
if type(sig) != tuple:
# TODO knewbury error handling
# TODO add error handling?
raise SignatureMismatch()
# Destructure this dictionary
@@ -160,10 +161,8 @@ def _destructure_dict(typegraph: Typegraph, node, tree):
type_fields = typegraph.fields[node]
if tree_fields == type_fields:
_destructure_dict_1(typegraph, node, tree)
# TODO knewbury error handling here
elif set(tree_fields).issuperset(set(type_fields)):
# Log a warning
# log.warning("XX: Tree has unrecognized fields")
logging.warning('Input tree has unrecognized fields, collecting only '
'known entries: {}'.format(tree))
logging.warning('tree fields: {}'.format(sorted(tree_fields)))
@@ -189,7 +188,6 @@ def _destructure_dict(typegraph: Typegraph, node, tree):
)
else:
# TODO knewbury error handling
status_writer.unknown_sarif_parsing_shape["extra_info"] = "type fields {} do not match tree fields {}.".format(type_fields, tree_fields)
status_writer.csv_write(status_writer.unknown_sarif_parsing_shape)
raise Exception("typegraph: unhandled case reached: cannot match type "