From 5010901b5f271d321107181d133c0f4d8b6c504c Mon Sep 17 00:00:00 2001 From: nyanloutre Date: Thu, 15 Aug 2019 11:11:49 +0200 Subject: [PATCH] Catch exception when overwriting config --- mautrix/util/config.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mautrix/util/config.py b/mautrix/util/config.py index 11d432ad..ec15c4a7 100644 --- a/mautrix/util/config.py +++ b/mautrix/util/config.py @@ -8,12 +8,15 @@ from ruamel.yaml.comments import CommentedMap from abc import ABC, abstractmethod import io +import logging yaml = YAML() yaml.indent(4) T = TypeVar('T') +log: logging.Logger = logging.getLogger("mau.util.config") + class RecursiveDict(Generic[T]): def __init__(self, data: Optional[T] = None, dict_factory: Optional[Type[T]] = None) -> None: @@ -209,5 +212,8 @@ def load_base(self) -> Optional[RecursiveDict[CommentedMap]]: return None def save(self) -> None: - with open(self.path, 'w') as stream: - yaml.dump(self._data, stream) + try: + with open(self.path, 'w') as stream: + yaml.dump(self._data, stream) + except OSError: + log.exception(f"Failed to overwrite the config in {self.path}")