Skip to content

Commit

Permalink
Merge pull request #11 from nyanloutre/catch_save_config_exception
Browse files Browse the repository at this point in the history
Catch exception when overwriting config
  • Loading branch information
tulir authored Aug 17, 2019
2 parents e5a2b81 + 5010901 commit da74a74
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions mautrix/util/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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}")

0 comments on commit da74a74

Please sign in to comment.