Skip to content

Commit df87bdd

Browse files
feat: add RoutingError exception class and export
1 parent 936454a commit df87bdd

4 files changed

Lines changed: 28 additions & 0 deletions

File tree

src/yamltrip/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ParseError,
1515
PatchError,
1616
QueryError,
17+
RoutingError,
1718
YAMLTripError,
1819
)
1920

@@ -52,6 +53,7 @@ def edit(path: str | Path) -> Editor:
5253
"PatchError",
5354
"QueryError",
5455
"Route",
56+
"RoutingError",
5557
"YAMLTripError",
5658
"edit",
5759
"load",

src/yamltrip/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,9 @@ class KeyMissingError(PatchError):
2525
"""Raised by replace() when the key doesn't exist."""
2626

2727

28+
class RoutingError(PatchError):
29+
"""Raised when a key path passes through a non-mapping node."""
30+
31+
2832
class NodeTypeError(PatchError, TypeError):
2933
"""Raised when a node is not the expected type for the operation."""

tests/test_errors.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
ParseError,
88
PatchError,
99
QueryError,
10+
RoutingError,
1011
YAMLTripError,
1112
)
1213

@@ -38,3 +39,23 @@ def test_raise_and_catch_base(self):
3839
msg = "key already exists"
3940
with pytest.raises(YAMLTripError, match=msg):
4041
raise KeyExistsError(msg)
42+
43+
44+
class TestRoutingErrorHierarchy:
45+
def test_routing_error_is_patch_error(self):
46+
assert issubclass(RoutingError, PatchError)
47+
48+
def test_routing_error_is_not_type_error(self):
49+
assert not issubclass(RoutingError, TypeError)
50+
51+
def test_routing_error_is_not_node_type_error(self):
52+
assert not issubclass(RoutingError, NodeTypeError)
53+
54+
def test_raise_and_catch_as_patch_error(self):
55+
msg = "route through scalar"
56+
with pytest.raises(PatchError):
57+
raise RoutingError(msg)
58+
59+
def test_message(self):
60+
err = RoutingError("Route passes through a non-mapping node at a")
61+
assert "a" in str(err)

tests/test_public_api.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def test_error_classes(self):
3939
assert issubclass(yamltrip.PatchError, yamltrip.YAMLTripError)
4040
assert issubclass(yamltrip.KeyExistsError, yamltrip.PatchError)
4141
assert issubclass(yamltrip.KeyMissingError, yamltrip.PatchError)
42+
assert issubclass(yamltrip.RoutingError, yamltrip.PatchError)
4243

4344
def test_core_types(self):
4445
assert yamltrip.Location is not None

0 commit comments

Comments
 (0)