catch exception if config file can't be read

This commit is contained in:
2024-05-23 14:05:57 +02:00
parent 01dbe2221d
commit 91c4c361c5

View File

@ -70,8 +70,13 @@ def read_config(configpath: str) -> Dict[str, Any]:
return {}
yaml = YAML(typ='safe', pure=True) # Set type to 'safe' and use pure Python mode
yaml.Constructor = MySafeConstructor
with open(filepath) as file:
yaml_config = yaml.load(file)
with open(filepath) as file:
try:
yaml_config = yaml.load(file)
except:
logging.error(f"Error reading config file {filepath}")
return {}
if not yaml_config:
logging.warning(f"config file {filepath} is empty")
return {}