Skip to content

Commit 93b1b30

Browse files
committed
print non-fatal error if metadata is not available
1 parent ef3b750 commit 93b1b30

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

misc/scripts/resolve-code-scanning-query-packs.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ def single_spaces(input):
7878
"""
7979
return " ".join(input.split())
8080

81+
def get_query_metadata(key, metadata, queryfile):
82+
"""Returns query metadata or prints a warning to stderr if a particular piece of metadata is not available."""
83+
if key in metadata: return single_spaces(metadata[key])
84+
query_id = metadata['id'] if 'id' in metadata else 'unknown'
85+
print("Warning: no '%s' metadata for query with ID '%s' (%s)" % (key, query_id, queryfile), file=sys.stderr)
86+
return ""
87+
8188
# Check for `git`
8289
git_version = subprocess.run("git --version", shell=True, capture_output=True, text=True)
8390
if (git_version.returncode != 0):
@@ -125,8 +132,12 @@ def single_spaces(input):
125132

126133
# Python's CSV writer will automatically quote fields if necessary
127134
csvwriter.writerow([
128-
queryfile_nwo, pack, single_spaces(meta['name']), meta['id'],
129-
meta["kind"], meta["problem.severity"], meta["precision"],
130-
single_spaces(meta["tags"])
135+
queryfile_nwo, pack,
136+
get_query_metadata('name', meta, queryfile_nwo),
137+
get_query_metadata('id', meta, queryfile_nwo),
138+
get_query_metadata('kind', meta, queryfile_nwo),
139+
get_query_metadata('problem.severity', meta, queryfile_nwo),
140+
get_query_metadata('precision', meta, queryfile_nwo),
141+
get_query_metadata('tags', meta, queryfile_nwo)
131142
])
132143

0 commit comments

Comments
 (0)