-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd68779
commit 080b39c
Showing
1 changed file
with
8 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
schema. This script can handle files from various sources (local, cloud storage) through | ||
smart_open, and logs validation errors while allowing for command-line configured | ||
verbosity. | ||
In cases of validation errors, the offending JSON object is logged and skipped. The | ||
script exits with a non-zero status if any validation errors are encountered. | ||
""" | ||
|
||
__author__ = "[email protected]" | ||
|
@@ -56,6 +59,7 @@ def __init__( | |
|
||
self.input_files = input_files | ||
self.file_format = file_format | ||
self.validation_errors = 0 | ||
self.output_writer = ( | ||
smart_open.open(output_file, mode="w", encoding="utf-8") | ||
if output_file | ||
|
@@ -68,6 +72,9 @@ def run(self) -> None: | |
"""Starts the validation process.""" | ||
|
||
self.process() | ||
if self.validation_errors > 0: | ||
log.error("Validation errors encountered: %d", self.validation_errors) | ||
sys.exit(1) | ||
|
||
def process(self) -> None: | ||
""" | ||
|
@@ -83,6 +90,7 @@ def process(self) -> None: | |
except jsonschema.exceptions.ValidationError as e: | ||
log.error("Validation error: %s", e.message) | ||
log.info("Offending JSON object ignored: %s", jo) | ||
self.validation_errors += 1 | ||
continue | ||
print( | ||
json.dumps(jo, ensure_ascii=False, separators=(",", ":")), | ||
|