Skip to content

Commit

Permalink
Gracefully handle missing configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Bozydarek committed Jul 14, 2024
1 parent 54bc7b2 commit f3a9223
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions data_processor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import csv
import yaml

Expand All @@ -11,7 +12,7 @@
from util import print_err, print_wrn, print_note

RE_RETRIEVE_RATIO = 0.8 # 80% of cumulated energy sent to the grid

CONFIG_FILE_PATH = "config.yml"

# From python3.11 'StrEnum' can be used
class DataTypes(str, Enum):
Expand Down Expand Up @@ -190,7 +191,10 @@ def load_cache() -> list[DataPoint]:


def load_config() -> dict[str, Any]:
with open("config.yml", 'r') as config_file:
if not os.path.isfile(CONFIG_FILE_PATH):
print_err(f"Configuration file ({CONFIG_FILE_PATH}) not found!")

with open(CONFIG_FILE_PATH, 'r') as config_file:
try:
config = yaml.safe_load(config_file)
except yaml.YAMLError as e:
Expand Down

0 comments on commit f3a9223

Please # to comment.