Skip to content

Commit

Permalink
default behavior was to silently log errors. Now it will throw , unle…
Browse files Browse the repository at this point in the history
…ss passsed a cli flag to not throw errors
  • Loading branch information
MohitYadav-codes committed May 15, 2024
1 parent 55338b6 commit 12d0a15
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
16 changes: 12 additions & 4 deletions akm_tools/akm_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ def create_and_combine_json_from_a_folder(dir_path):
return list_to_return


def parse_and_validate_data(model_folder, schema, extended_schema_dir, overlays):
def parse_and_validate_data(model_folder, schema, extended_schema_dir, overlays,silent_mode):
model_data_list = create_and_combine_json_from_a_folder(model_folder)
overlay_data_list = create_and_combine_json_from_a_folder(overlays)
all_data = model_data_list + overlay_data_list
validator_object = AKMDataValidator(schema=schema)
validated_model_data = validator_object.validate_data_instances(all_data, extended_schema_dir=extended_schema_dir)
validated_model_data = validator_object.validate_contexts(all_data=validated_model_data) ## passing valid instances
validator_object.log_errors()

validator_object.log_errors(silent_mode)
return validated_model_data


Expand Down Expand Up @@ -94,6 +94,14 @@ def main():
choices=export_functions.keys(),
help="Specifies the export format",
)

## export options
parser.add_argument(
"--silent_mode",
action="store_true",
help="log but dont throw errors",
default=False
)
parser.add_argument("-f", "--export_file_path", type=str, help="Path for export file")
args = parser.parse_args()

Expand All @@ -103,7 +111,7 @@ def main():
with open(args.schema, "r") as f:
schema = json.load(f)
validated_model_data = parse_and_validate_data(
args.model_data_folder, schema, args.extended_schema_dir, args.extended_data_dir
args.model_data_folder, schema, args.extended_schema_dir, args.extended_data_dir,args.silent_mode
)

if args.export_format:
Expand Down
5 changes: 4 additions & 1 deletion akm_tools/validation/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,12 @@ def _configure_data_instance_validators(self):
]
return data_instance_validator_objects

def log_errors(self):
def log_errors(self,silent_mode):
for error_msg in self.validation_errors:
logging.error(error_msg)
if len (self.validation_errors)>0:
if not(silent_mode):
raise Exception('There were errors during vaidaiton, please check the log file')

def validate_contexts(self, all_data: List[Dict]):
print("Validating Data Contexts")
Expand Down

0 comments on commit 12d0a15

Please sign in to comment.