Skip to content

Commit

Permalink
Continue after validation errors to validate all files
Browse files Browse the repository at this point in the history
  • Loading branch information
DasSkelett committed Dec 16, 2019
1 parent 7f350fc commit 3afe16c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
16 changes: 16 additions & 0 deletions tests/workspaces/default/recursiveness/failing-validation.version
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"NAME": "KSP-AVC Version File Validator",
"URL": "https://github.com/DasSkelett/AVC-VersionFileValidator",
"DOWNLOAD": "https://github.com/DasSkelett/AVC-VersionFileValidator/releases",
"GITHUB": {
"USERNAME": "DasSkelett",
"REPOSITORY": "AVC-VersionFileValidator"
},
"VERSION": {
"MAJOR": 0,
"MINOR": 0,
"PATCH": 0,
"BUILD": 1
},
"KSP_VERSION": "*"
}
35 changes: 24 additions & 11 deletions validator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,26 +29,39 @@ def main():
# How to lazy-get this only when version_files is not empty (which is a generator)?
schema = get_schema()

failed = False
failed_files = []

for f in version_files:
with f.open('r') as vf:
try:
print(f'Loading {f}')
print(f'\nLoading {f}')
try:
with f.open('r') as vf:
json_file = json.load(vf)
except json.decoder.JSONDecodeError as e:
print('Failed loading JSON file. Check for syntax errors around the mentioned line:')
print(e.msg)
exit(1)
except json.decoder.JSONDecodeError as e:
print('Failed loading JSON file. Check for syntax errors around the mentioned line:')
print(e.msg)
failed = True
failed_files.append(f.name)
continue

print(f'Validating {f}')
try:
print(f'Validating {f}')
jsonschema.validate(json_file, schema)
except jsonschema.ValidationError as e:
print('Validation failed, see message below:')
print('Validation failed:')
print(e.message)
exit(1)
failed = True
failed_files.append(f.name)
continue
print('Validation successful')

print('Done!')
exit(0)
if failed:
print('\nThe following files failed validation:')
print(failed_files)
exit(1)
else:
exit(0)


def get_schema():
Expand Down

0 comments on commit 3afe16c

Please sign in to comment.