9
9
import jsonpath_ng .ext
10
10
import jsonpointer
11
11
import yaml
12
+ import yaml .parser
12
13
import re
13
14
import jsonpatch
14
15
from functools import reduce
@@ -111,14 +112,20 @@ def resolve_path(path : Path) -> Optional[Path]:
111
112
resolved_schema_path = resolve_path (path .resolve ())
112
113
if resolved_schema_path :
113
114
with resolved_schema_path .open (mode = 'r' ) as fp :
114
- return json .load (fp )
115
+ try :
116
+ return json .load (fp )
117
+ except json .decoder .JSONDecodeError as e :
118
+ print_failure (f"Failed to load schema with error \" { e .msg } \" at { resolved_schema_path } :{ e .lineno } :{ e .colno } !" )
115
119
else :
116
120
return None
117
121
118
122
def load_config (path : Path ) -> Optional [Mapping [str , Any ]]:
119
123
if path .is_file ():
120
124
with path .open ('r' ) as fp :
121
- return yaml .safe_load (fp )
125
+ try :
126
+ return yaml .safe_load (fp )
127
+ except yaml .parser .ParserError as e :
128
+ print_failure (f"Failed to load config with error \" { e .problem } \" at { path } :{ e .problem_mark .line } :{ e .problem_mark .column } !" )
122
129
else :
123
130
return None
124
131
@@ -137,17 +144,23 @@ def main(args: argparse.Namespace):
137
144
if not coding_standards_schema :
138
145
print_failure ("Failed to load Coding Standards schema!" )
139
146
147
+ if not '$id' in coding_standards_schema :
148
+ print_failure (f"Missing id for Coding Standards schema: '{ args .coding_standards_schema_file } '" )
149
+
140
150
if coding_standards_schema ['$id' ] != CODING_STANDARDS_SCHEMA_ID :
141
151
print_failure (f"Unexpected id for Coding Standards schema, expecting '{ CODING_STANDARDS_SCHEMA_ID } '!" )
142
152
143
153
sarif_schema = load_schema (args .sarif_schema_file , 'sarif-schema-2.1.0.json' )
144
154
if not sarif_schema :
145
- print ("Failed to load Sarif schema!" , file = sys .stderr )
155
+ print (f "Failed to load Sarif schema: ' { args . sarif_schema_file } ' !" , file = sys .stderr )
146
156
sys .exit (1 )
147
157
sarif_schema = cast (Mapping [str , Any ], sarif_schema )
148
158
159
+ if not '$id' in sarif_schema :
160
+ print_failure (f"Missing id for Sarif schema: '{ args .sarif_schema_file } '" )
161
+
149
162
if sarif_schema ['$id' ] != SARIF_SCHEMA_ID :
150
- print_failure (f"Unexpected id for Sarif schema, expecting '{ SARIF_SCHEMA_ID } '!" )
163
+ print_failure (f"Unexpected id for Sarif schema: ' { args . sarif_schema_file } , expecting '{ SARIF_SCHEMA_ID } '!" )
151
164
152
165
coding_standards_config = load_config (args .coding_standards_config_file )
153
166
if not coding_standards_schema :
0 commit comments