Skip to content

Commit 298725c

Browse files
fix: raise NodeTypeError on scalar traversal, remove broken spec reference
1 parent 6636601 commit 298725c

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

doc/specs/2026-05-22-deep-merge-design.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# Design: Deep Merge (`merge()`)
22

33
**Date:** 2026-05-22
4-
**Status:** Approved
5-
**Relates to:** `doc/todo/feature-deep-merge.md`
4+
**Status:** Approved
65

76
## Summary
87

src/yamltrip/document.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,12 @@ def merge(self, *keys: KeyPart, value: Any) -> Document:
562562
if normalized:
563563
route = _make_route(normalized)
564564
if not self._core_doc.query_exists(route):
565-
return self.upsert(*normalized, value=value)
565+
try:
566+
return self.upsert(*normalized, value=value)
567+
except PatchError as e:
568+
if "unexpected node" in str(e):
569+
raise NodeTypeError(str(e)) from None
570+
raise
566571

567572
# Get current value and diff
568573
try:

tests/test_merge.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from yamltrip import edit
44
from yamltrip.document import Document
5-
from yamltrip.errors import PatchError
5+
from yamltrip.errors import NodeTypeError
66

77

88
class TestMergeMapping:
@@ -108,7 +108,7 @@ def test_editor_merge(self, tmp_path):
108108

109109
class TestMergeErrors:
110110
def test_merge_through_scalar_raises(self):
111-
"""Merging through a scalar path raises PatchError."""
111+
"""Merging through a scalar path raises NodeTypeError."""
112112
doc = Document("a:\n b: 1\n")
113-
with pytest.raises(PatchError):
113+
with pytest.raises(NodeTypeError):
114114
doc.merge("a", "b", "c", value={"x": 1})

0 commit comments

Comments
 (0)