Skip to content

Commit 51f49b6

Browse files
committed
fix: wrap frozen utility methods in try-catch
1 parent 9bbf839 commit 51f49b6

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

libdestruct/common/obj.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,24 @@ def freeze(self: obj) -> None:
7474

7575
def diff(self: obj) -> tuple[object, object]:
7676
"""Return the difference between the current value and the frozen value."""
77-
return self._frozen_value, self.get()
77+
try:
78+
return self._frozen_value, self.get()
79+
except ValueError as e:
80+
raise RuntimeError("Could not calculate the diff the object.") from e
7881

7982
def reset(self: obj) -> None:
8083
"""Reset the object to its frozen value."""
81-
self._set(self._frozen_value)
84+
try:
85+
self._set(self._frozen_value)
86+
except ValueError as e:
87+
raise RuntimeError("Could not reset the object to its frozen value.") from e
8288

8389
def update(self: obj) -> None:
8490
"""Update the object with the given value."""
85-
self._frozen_value = self.get()
91+
try:
92+
self._frozen_value = self.get()
93+
except ValueError as e:
94+
raise RuntimeError("Could not update the object.") from e
8695

8796
@property
8897
def value(self: obj) -> object:

0 commit comments

Comments
 (0)