Skip to content

Commit 7bae785

Browse files
committed
improve error handling
Signed-off-by: Zen <[email protected]>
1 parent c3950d6 commit 7bae785

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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 = "zenlib"
7-
version = "2.0.3"
7+
version = "2.0.4"
88
authors = [
99
{ name="Desultory", email="[email protected]" },
1010
]

src/zenlib/util/check_dict.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = "desultory"
2-
__version__ = "1.1.0"
2+
__version__ = "1.2.0"
33

44

55
from functools import wraps
@@ -60,7 +60,14 @@ def dispatch_msg(msg):
6060
if not_empty and not dict_val:
6161
return dispatch_msg("[%s] Key is empty: %s" % (func.__name__, key))
6262
elif isinstance(key, dict):
63-
if dict_val := walk_dict(validate_dict, key, fail_safe=not raise_exception):
63+
try:
64+
dict_val = walk_dict(validate_dict, key)
65+
except KeyError:
66+
if not unset:
67+
return dispatch_msg("[%s] Unable to find search key: %s." % (func.__name__, key))
68+
else:
69+
dict_val = None
70+
if dict_val:
6471
if unset and not contains:
6572
return dispatch_msg("[%s] Key is set when it should be unset: %s." % (func.__name__, dict_val))
6673
if not_empty and not dict_val:

0 commit comments

Comments
 (0)