mirror of
https://github.com/hohn/sarif-cli.git
synced 2025-12-16 17:23:03 +01:00
Add quick check to verify that input is serif
An occasional output from LGTM is
{"code":404,"error":"The specified analysis could not be found"}
With this patch, the csv output is now
"ERROR","invalid json contents %s","some-file.json"
and the plain text output becomes
ERROR: invalid json contents in some-file.json
This commit is contained in:
committed by
=Michael Hohn
parent
120e673424
commit
92d904ee10
@@ -23,6 +23,14 @@ with open(args.file, 'r') if args.file != '-' else sys.stdin as fp:
|
||||
if args.csv:
|
||||
cw = S.get_csv_writer()
|
||||
|
||||
if not S.is_sarif_struct(sarif_struct):
|
||||
if args.csv:
|
||||
S.write_csv(cw, "ERROR", "invalid json contents %s", args.file)
|
||||
else:
|
||||
S.msg("ERROR: invalid json contents in %s\n" % (args.file))
|
||||
S.dbg("invalid json contents in %s\n" % (args.file))
|
||||
sys.exit(0) # No failure, just a warning
|
||||
|
||||
for runi in S.indices(sarif_struct, 'runs'):
|
||||
num_results = len(S.get(sarif_struct, 'runs', runi, 'results'))
|
||||
if num_results == 0: continue
|
||||
|
||||
@@ -18,6 +18,12 @@ class NoFile:
|
||||
whole file is to be used.
|
||||
"""
|
||||
|
||||
def is_sarif_struct(struct):
|
||||
"""A quick check to verify that `struct` is in fact a SARIF tree.
|
||||
"""
|
||||
return type(struct) == dict and "$schema" in struct and \
|
||||
"sarif" in struct["$schema"] and "version" in struct
|
||||
|
||||
def get_csv_writer():
|
||||
""" Set up and return the default csv writer on stdout.
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user