Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch exception when overwriting config #11

Merged
merged 1 commit into from
Aug 17, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}")