jekyll-to-hugo/app/utils.py
2023-05-29 21:35:38 +03:00

28 lines
568 B
Python

import contextlib
@contextlib.contextmanager
def key_error_silence():
"""
Context manager that silences key errors exceptions.
"""
try:
yield
except KeyError:
pass
def guard_against_none_or_empty_str(value: str, name: str):
"""
Guard against None or empty string.
Parameters:
----------
value: str
The value to check.
name: str
The name of the value.
"""
if value is None or not isinstance(value, str) or value == "":
raise ValueError(f"{name} cannot be None or empty")