summaryrefslogtreecommitdiff
path: root/kvmd/yamlconf
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-09-09 03:26:15 +0300
committerDevaev Maxim <[email protected]>2020-09-09 03:26:15 +0300
commit9c78f4f631facc41df099e5b6b318d0b9e665adc (patch)
tree67494eb1b5e654fcbd9a4d1d54639b3f898b346b /kvmd/yamlconf
parent081797b2536149b41ca513e64c20de8ee40f5b6e (diff)
catch manual validation
Diffstat (limited to 'kvmd/yamlconf')
-rw-r--r--kvmd/yamlconf/__init__.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/kvmd/yamlconf/__init__.py b/kvmd/yamlconf/__init__.py
index a253d449..9de5bee3 100644
--- a/kvmd/yamlconf/__init__.py
+++ b/kvmd/yamlconf/__init__.py
@@ -20,11 +20,13 @@
# ========================================================================== #
+import contextlib
import json
from typing import Tuple
from typing import List
from typing import Dict
+from typing import Generator
from typing import Callable
from typing import Optional
from typing import Any
@@ -129,6 +131,14 @@ class Option:
# =====
+def manual_validated(value: Any, *path: str) -> Generator[None, None, None]:
+ try:
+ yield
+ except (TypeError, ValueError) as err:
+ raise ConfigError(f"Invalid value {value!r} for key {'/'.join(path)!r}: {err}")
+
+
def make_config(raw: Dict[str, Any], scheme: Dict[str, Any], _keys: Tuple[str, ...]=()) -> Section:
if not isinstance(raw, dict):
raise ConfigError(f"The node {('/'.join(_keys) or '/')!r} must be a dictionary")