mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
Fix for KeyError: 'region', caused by result without region
Region / line / column information are present in most messages. The one that
caused this error refers to the whole file:
ipdb> p sarif_struct
{'ruleId': 'com.lgtm/cpp-queries:cpp/missing-header-guard', 'ruleIndex': 12,
'message': {'text': 'This header file should contain a header guard to prevent
multiple inclusion.'}, 'locations': [{'physicalLocation': {'artifactLocation':
{'uri': 'diff/cmpbuf.h', 'uriBaseId': '%SRCROOT%', 'index': 13}}}],
'partialFingerprints': {'primaryLocationLineHash': 'd04cb834fa64727d:1',
'primaryLocationStartColumnFingerprint': '0'}}
The goal is fixed-structure output formatting, so whole-file output uses
-1,-1,-1,-1 for line, column information.
This commit is contained in:
committed by
=Michael Hohn
parent
ffcacec630
commit
2c3ca3c0eb
@@ -33,14 +33,22 @@ def get_relatedlocation_message_info(related_location):
|
||||
region = get(related_location, 'physicalLocation', 'region')
|
||||
return message, artifact, region
|
||||
|
||||
class WholeFile:
|
||||
pass
|
||||
|
||||
def get_location_message_info(result):
|
||||
""" Given one of the results, extract message information.
|
||||
|
||||
The `result` typically starts from get(sarif_struct, 'runs', run_index, 'results', res_index)
|
||||
|
||||
Returns: (message, artifact, region)
|
||||
For an empty 'region' key, returns (message, artifact, sarif_cli.WholeFile)
|
||||
|
||||
"""
|
||||
message = get(result, 'message', 'text')
|
||||
artifact = get(result, 'locations', 0, 'physicalLocation', 'artifactLocation')
|
||||
region = get(result, 'locations', 0, 'physicalLocation', 'region')
|
||||
# If there is no 'region' key, use the whole file
|
||||
region = get(result, 'locations', 0, 'physicalLocation').get('region', WholeFile)
|
||||
return (message, artifact, region)
|
||||
|
||||
def display_underlined(l1, c1, l2, c2, line, line_num):
|
||||
|
||||
Reference in New Issue
Block a user