Skip to content

Commit a0a40cd

Browse files
committed
Handle schema validation exception
1 parent a4d2e3a commit a0a40cd

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

scripts/guideline_recategorization/recategorize.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,18 @@ def main(args: argparse.Namespace):
155155
sys.exit(1)
156156

157157
coding_standards_config = cast(Mapping[str, Any], coding_standards_config)
158-
validate_against_schema(coding_standards_schema, coding_standards_config)
158+
try:
159+
validate_against_schema(coding_standards_schema, coding_standards_config)
160+
except jsonschema.ValidationError as e:
161+
print(f"Failed to validate the Coding Standards configuration file: {args.coding_standards_config_file} with the message: '{e.message}'!", file=sys.stderr)
162+
sys.exit(1)
159163

160164
sarif = json.load(args.sarif_in)
161-
validate_against_schema(sarif_schema, sarif)
165+
try:
166+
validate_against_schema(sarif_schema, sarif)
167+
except jsonschema.ValidationError as e:
168+
print(f"Failed to validate the provided Sarif with the message: '{e.message}'!", file=sys.stderr)
169+
sys.exit(1)
162170

163171
recategorizations = get_guideline_recategorizations(coding_standards_config)
164172
patch = jsonpatch.JsonPatch([patch for r in recategorizations for patch in generate_json_patches_for_recategorization(r, sarif)])

0 commit comments

Comments
 (0)