Skip to content

Commit c6b888b

Browse files
committed
Better error message for implicit branches
Fixes #407 Signed-off-by: Erik Jaegervall <[email protected]>
1 parent 770a7a3 commit c6b888b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

src/vss_tools/model.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def as_dict(
109109
class VSSData(VSSRaw):
110110
model_config = ConfigDict(extra="allow")
111111
type: NodeType
112-
description: str
112+
description: str = ""
113113
comment: str | None = None
114114
delete: bool = False
115115
deprecation: str | None = None
@@ -126,6 +126,18 @@ def check_const_uid_format(cls, v: str | None) -> str | None:
126126
assert bool(re.match(pattern, v)), f"'{v}' is not a valid 'constUID'"
127127
return v
128128

129+
@field_validator("description", mode="before")
130+
@classmethod
131+
def ensure_description(cls, value: Any) -> Any:
132+
"""Give better explanation for empty description."""
133+
134+
if value == "":
135+
raise ValueError(
136+
"all nodes in the final tree must have a description. "
137+
"Implicit branches are not allowed in final tree!"
138+
)
139+
return value
140+
129141

130142
class VSSDataBranch(VSSData):
131143
instances: Any = None

tests/vspec/test_description_error/test_description_error.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ def test_description_error(vspec_file: str, type_file: str, type_out_file: str,
4040
assert process.returncode != 0
4141
log_content = log.read_text()
4242
print(log_content)
43-
assert "'type': 'missing'" in log_content
43+
assert "'type': 'value_error'" in log_content
4444
assert "1 model error(s):" in log_content

tests/vspec/test_overlay/test_overlay.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,5 @@ def test_overlay_branch_error(tmp_path):
7171
assert process.returncode != 0
7272
log_content = log.read_text()
7373
assert "'A.AB' has 1 model error(s)" in log_content
74-
assert "'type': 'missing'" in log_content
74+
assert "'type': 'value_error'" in log_content
7575
assert "description" in log_content

0 commit comments

Comments
 (0)