Skip to content

Commit 41186fe

Browse files
authored
Merge pull request #360 from ma10/freee_a11y_gl-improve-error-messages-20250617
freee_a11y_gl: improve error messages for cases where nonexistent items are referenced.
2 parents 00c3142 + 95249ca commit 41186fe

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

tools/lib/freee_a11y_gl/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "freee_a11y_gl"
7-
version = "0.1.1"
7+
version = "0.1.2"
88
description = "A module to process a11y guidelines data"
99
authors = [
1010
{name = "Masafumi NAKANE", email = "[email protected]"}

tools/lib/freee_a11y_gl/src/freee_a11y_gl/models/content.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,22 @@ def __init__(self, gl: Dict[str, Any]):
9999

100100
# Set up relationships
101101
rel = RelationshipManager()
102+
if not Category.get_by_id(gl['category']):
103+
raise ValueError(f'Category ID {gl["category"]} referenced in guideline {self.id} does not exist.')
102104
rel.associate_objects(self, Category.get_by_id(gl['category']))
103105

104106
# Associate checks
105107
for check_id in gl.get('checks', []):
106108
from .check import Check # Import here to avoid circular imports
109+
if not Check.get_by_id(check_id):
110+
raise ValueError(f'Check ID {check_id} referenced in guideline {self.id} does not exist.')
107111
rel.associate_objects(self, Check.get_by_id(check_id))
108112

109113
# Associate WCAG success criteria
110114
for sc in gl.get('sc', []):
111115
from .reference import WcagSc # Import here to avoid circular imports
116+
if not WcagSc.get_by_id(sc):
117+
raise ValueError(f'Success criterion ID {sc} referenced in guideline {self.id} does not exist.')
112118
rel.associate_objects(self, WcagSc.get_by_id(sc))
113119

114120
# Associate info references

tools/lib/freee_a11y_gl/src/freee_a11y_gl/models/faq/article.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,24 @@ def _create_relationships(self, faq: Dict[str, Any]) -> None:
4545
# Associate tags
4646
from .tag import FaqTag
4747
for tag_id in faq['tags']:
48+
if not FaqTag.get_by_id(tag_id):
49+
raise ValueError(f'Tag ID {tag_id} referenced in FAQ {self.id} does not exist.')
4850
rel.associate_objects(self, FaqTag.get_by_id(tag_id))
4951

5052
# Associate guidelines if present
5153
if 'guidelines' in faq:
5254
from ..content import Guideline
5355
for gl_id in faq['guidelines']:
56+
if not Guideline.get_by_id(gl_id):
57+
raise ValueError(f'Guideline ID {gl_id} referenced in FAQ {self.id} does not exist.')
5458
rel.associate_objects(self, Guideline.get_by_id(gl_id))
5559

5660
# Associate checks if present
5761
if 'checks' in faq:
5862
from ..check import Check
5963
for check_id in faq['checks']:
64+
if not Check.get_by_id(check_id):
65+
raise ValueError(f'Check ID {check_id} referenced in FAQ {self.id} does not exist.')
6066
rel.associate_objects(self, Check.get_by_id(check_id))
6167

6268
# Associate info references if present

0 commit comments

Comments
 (0)