Skip to content

Commit

Permalink
Ensure reading from empty config file results in empty dict
Browse files Browse the repository at this point in the history
  • Loading branch information
okomestudio committed Apr 22, 2020
1 parent 96eba75 commit 2fc94fa
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/resconfig/io/paths.py
@@ -1,3 +1,4 @@
from logging import getLogger
from pathlib import Path

from ..typing import FilePath
Expand All @@ -6,6 +7,8 @@
from . import toml
from . import yaml

log = getLogger(__name__)


class ConfigPath(type(Path())):
"""Path for configuration file."""
Expand All @@ -18,7 +21,12 @@ def dump(self, content):

def load(self):
with open(self) as f:
return self.module.load(f)
try:
content = self.module.load(f) or {}
except Exception:
log.exception("Error occured loading from %s; assume empty...", self)
content = {}
return content

@classmethod
def from_extension(cls, filename: FilePath) -> "ConfigPath":
Expand Down

0 comments on commit 2fc94fa

Please sign in to comment.