Skip to content

Commit

Permalink
Fix behaviour of io.read_yaml function when config file path is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
HealthyPear committed Oct 31, 2024
1 parent 5a3dcdd commit 80f8947
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/iact_estimator/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def read_yaml(input_file_path):
Parameters
----------
input_file_path : `str`
input_file_path : `str` or `pathlib.Path`
Path to the input YAML file.
Returns
Expand All @@ -31,11 +31,14 @@ def read_yaml(input_file_path):
Contents of the YAML file in form
of a Python dictionary.
"""
try:
with open(input_file_path, "r") as input_file:
data = load(input_file, Loader=Loader)
except FileNotFoundError:
logger.exception("Configuration file not found at %s", input_file_path)

input_file_path = Path(input_file_path).resolve()
if not input_file_path.is_file():
raise ValueError(f"Configuration file not found at {input_file_path}")

with open(input_file_path, "r") as input_file:
data = load(input_file, Loader=Loader)

return data


Expand Down

0 comments on commit 80f8947

Please sign in to comment.