mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
Improve error handling on signature mismatch cases
and cleanup old todos that have been addressed
This commit is contained in:
@@ -43,7 +43,6 @@ def load(fname):
|
|||||||
try:
|
try:
|
||||||
content = json.load(fp)
|
content = json.load(fp)
|
||||||
except json.decoder.JSONDecodeError as err:
|
except json.decoder.JSONDecodeError as err:
|
||||||
# TODO knewbury error handling
|
|
||||||
logging.error('Error reading from {}: {}: line {}, column {}'
|
logging.error('Error reading from {}: {}: line {}, column {}'
|
||||||
.format(fname, err.msg, err.lineno, err.colno))
|
.format(fname, err.msg, err.lineno, err.colno))
|
||||||
status_writer.file_load_error["file"] = fname
|
status_writer.file_load_error["file"] = fname
|
||||||
@@ -69,18 +68,14 @@ sarif_struct = signature.fillsig(args, sarif_struct, context)
|
|||||||
|
|
||||||
#
|
#
|
||||||
# Use reference type graph (signature) to traverse sarif and attach values to tables
|
# Use reference type graph (signature) to traverse sarif and attach values to tables
|
||||||
#
|
try:
|
||||||
# try:
|
tgraph = typegraph.Typegraph(signature_single.struct_graph_2022_02_01)
|
||||||
# tgraph = typegraph.Typegraph(signature_single.struct_graph_2022_02_01)
|
typegraph.destructure(tgraph, signature_single.start_node_2022_02_01, sarif_struct)
|
||||||
# typegraph.destructure(tgraph, signature_single.start_node_2022_02_01, sarif_struct)
|
except Exception:
|
||||||
# except json.decoder.JSONDecodeError as err:
|
# will have gathered errors/warnings
|
||||||
# logging.error('Error reading from {}: {}: line {}, column {}'
|
status_writer.csv_write_warnings()
|
||||||
# .format(args.file, err.msg, err.lineno, err.colno))
|
#pass the exception up to be put into log by runner
|
||||||
# sys.exit(1)
|
raise(Exception)
|
||||||
tgraph = typegraph.Typegraph(signature_single.struct_graph_2022_02_01)
|
|
||||||
typegraph.destructure(tgraph, signature_single.start_node_2022_02_01, sarif_struct)
|
|
||||||
# may have gathered warnings below, if not does nothing
|
|
||||||
status_writer.csv_write_warnings()
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Form output tables
|
# Form output tables
|
||||||
|
|||||||
@@ -126,7 +126,7 @@ def joins_for_scans(basetables, external_info, scantables):
|
|||||||
"id" : e.scan_id,
|
"id" : e.scan_id,
|
||||||
"commit_id" : b.project.revisionId[0],
|
"commit_id" : b.project.revisionId[0],
|
||||||
"project_id" : e.project_id,
|
"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_start" : pd.Timestamp(0.0, unit='s'),
|
||||||
"db_create_stop" : pd.Timestamp(0.0, unit='s'),
|
"db_create_stop" : pd.Timestamp(0.0, unit='s'),
|
||||||
"scan_start_date" : 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)
|
res = pd.concat(stack)
|
||||||
else:
|
else:
|
||||||
if stack == []:
|
if stack == []:
|
||||||
# TODO knewbury to error handling
|
|
||||||
logging.warning("Zero problem/path_problem results found in sarif "
|
logging.warning("Zero problem/path_problem results found in sarif "
|
||||||
"file but processing anyway.")
|
"file but processing anyway.")
|
||||||
status_writer.csv_write(status_writer.zero_results)
|
status_writer.csv_write(status_writer.zero_results)
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ def destructure(typegraph: Typegraph, node: NodeId, tree: Tree):
|
|||||||
elif t in [str, int, bool]:
|
elif t in [str, int, bool]:
|
||||||
pass
|
pass
|
||||||
else:
|
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)
|
raise Exception("Unhandled type: %s" % t)
|
||||||
|
|
||||||
def _destructure_dict_1(typegraph, node, tree):
|
def _destructure_dict_1(typegraph, node, tree):
|
||||||
@@ -139,7 +140,7 @@ def _destructure_dict_1(typegraph, node, tree):
|
|||||||
# Sanity check
|
# Sanity check
|
||||||
sig = typegraph.signature_graph[node]
|
sig = typegraph.signature_graph[node]
|
||||||
if type(sig) != tuple:
|
if type(sig) != tuple:
|
||||||
# TODO knewbury error handling
|
# TODO add error handling?
|
||||||
raise SignatureMismatch()
|
raise SignatureMismatch()
|
||||||
|
|
||||||
# Destructure this dictionary
|
# Destructure this dictionary
|
||||||
@@ -160,10 +161,8 @@ def _destructure_dict(typegraph: Typegraph, node, tree):
|
|||||||
type_fields = typegraph.fields[node]
|
type_fields = typegraph.fields[node]
|
||||||
if tree_fields == type_fields:
|
if tree_fields == type_fields:
|
||||||
_destructure_dict_1(typegraph, node, tree)
|
_destructure_dict_1(typegraph, node, tree)
|
||||||
# TODO knewbury error handling here
|
|
||||||
elif set(tree_fields).issuperset(set(type_fields)):
|
elif set(tree_fields).issuperset(set(type_fields)):
|
||||||
# Log a warning
|
# Log a warning
|
||||||
# log.warning("XX: Tree has unrecognized fields")
|
|
||||||
logging.warning('Input tree has unrecognized fields, collecting only '
|
logging.warning('Input tree has unrecognized fields, collecting only '
|
||||||
'known entries: {}'.format(tree))
|
'known entries: {}'.format(tree))
|
||||||
logging.warning('tree fields: {}'.format(sorted(tree_fields)))
|
logging.warning('tree fields: {}'.format(sorted(tree_fields)))
|
||||||
@@ -189,7 +188,6 @@ def _destructure_dict(typegraph: Typegraph, node, tree):
|
|||||||
)
|
)
|
||||||
|
|
||||||
else:
|
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.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)
|
status_writer.csv_write(status_writer.unknown_sarif_parsing_shape)
|
||||||
raise Exception("typegraph: unhandled case reached: cannot match type "
|
raise Exception("typegraph: unhandled case reached: cannot match type "
|
||||||
|
|||||||
Reference in New Issue
Block a user