Skip to content

Commit

Permalink
Add msg to all errors being raised
Browse files Browse the repository at this point in the history
  • Loading branch information
e-lo committed Oct 9, 2024
1 parent c5c321c commit d70a908
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion projectcard/bin/update_projectcard_schema
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
5 changes: 3 additions & 2 deletions projectcard/errors.py
Original file line number Diff line number Diff line change
@@ -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."""
Expand All @@ -19,4 +20,4 @@ class PycodeError(ProjectCardValidationError):


class ProjectCardJSONSchemaError(SchemaError):
"""Error in the ProjectCard json schema."""
"""Error in the ProjectCard json schema."""
9 changes: 6 additions & 3 deletions projectcard/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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}")
CardLogger.info(f"--Finished: {request.node.name}")

0 comments on commit d70a908

Please sign in to comment.