From d70a90819e78009b63106d2f19b620cd506410c0 Mon Sep 17 00:00:00 2001 From: Elizabeth Sall Date: Wed, 9 Oct 2024 16:35:09 -0700 Subject: [PATCH] Add msg to all errors being raised --- projectcard/bin/update_projectcard_schema | 1 - projectcard/errors.py | 5 +++-- projectcard/validate.py | 9 ++++++--- tests/test_docs.py | 6 +++--- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/projectcard/bin/update_projectcard_schema b/projectcard/bin/update_projectcard_schema index a4375cb..d29389e 100755 --- a/projectcard/bin/update_projectcard_schema +++ b/projectcard/bin/update_projectcard_schema @@ -1,5 +1,4 @@ #!/usr/bin/env python3 - """Updates older project cards to current format. If you have a project card that isn't successfully converting using this script or its wrapper, diff --git a/projectcard/errors.py b/projectcard/errors.py index 6140efd..6f93fbe 100644 --- a/projectcard/errors.py +++ b/projectcard/errors.py @@ -1,10 +1,11 @@ """Custom errors for projectcard package.""" + from jsonschema.exceptions import SchemaError, ValidationError class ProjectCardReadError(Exception): """Error in reading project card.""" - + class ProjectCardValidationError(ValidationError): """Error in formatting of ProjectCard.""" @@ -19,4 +20,4 @@ class PycodeError(ProjectCardValidationError): class ProjectCardJSONSchemaError(SchemaError): - """Error in the ProjectCard json schema.""" \ No newline at end of file + """Error in the ProjectCard json schema.""" diff --git a/projectcard/validate.py b/projectcard/validate.py index 37df0ac..81984dd 100644 --- a/projectcard/validate.py +++ b/projectcard/validate.py @@ -97,7 +97,8 @@ def validate_schema_file(schema_path: Path = PROJECTCARD_SCHEMA) -> bool: pass except SchemaError as e: CardLogger.error(e) - raise ProjectCardJSONSchemaError from e + msg = f"Schema error for projectcard schema." + raise ProjectCardJSONSchemaError(msg) from e return True @@ -173,10 +174,12 @@ def validate_card( msg = f"\nRelevant schema: {e.schema}\nValidator Value: {e.validator_value}\nValidator: {e.validator}" msg += f"\nabsolute_schema_path:{e.absolute_schema_path}\nabsolute_path:{e.absolute_path}" CardLogger.error(msg) - raise ProjectCardValidationError from e + msg = f"Validation error for project {jsondata['project']}" + raise ProjectCardValidationError(msg) from e except SchemaError as e: CardLogger.error(e) - raise ProjectCardJSONSchemaError from e + msg = f"Schema error for projectcard schema." + raise ProjectCardJSONSchemaError(msg) from e if "pycode" in jsondata: if "self." in jsondata["pycode"] and "self_obj_type" not in jsondata: diff --git a/tests/test_docs.py b/tests/test_docs.py index e88ffd4..79fa1f3 100644 --- a/tests/test_docs.py +++ b/tests/test_docs.py @@ -23,7 +23,7 @@ def test_jsonschema2md(request, test_out_dir): with out_md.open("w") as f: f.write(md) try: - markdown.markdown(md) + markdown.markdown(md) except Exception as e: pytest.fail(f"json_schema_to_md generated Invalid markdown: {e}") CardLogger.info(f"--Finished: {request.node.name}") @@ -36,7 +36,7 @@ def test_examples2md(request, example_dir, test_out_dir): with out_md.open("w") as f: f.write(md) try: - markdown.markdown(md) + markdown.markdown(md) except Exception as e: pytest.fail(f"card_list_to_table generated Invalid markdown: {e}") - CardLogger.info(f"--Finished: {request.node.name}") \ No newline at end of file + CardLogger.info(f"--Finished: {request.node.name}")