Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

Commit

Permalink
Merge pull request #73 from ethyca/sp-70-config-error
Browse files Browse the repository at this point in the history
[#70] Refactor error handling during unsuccessful config loading
  • Loading branch information
Paul Sanders authored Sep 28, 2022
2 parents 40ed0fa + 51054f2 commit 6083c7f
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions fideslib/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,26 +247,30 @@ def get_config(
This will fail on the first encountered bad conf file.
"""
try:
filenames_as_str = " or ".join([str(x) for x in file_names])
logger.info(
"Attempting to load application config from files: %s", filenames_as_str
)
return class_name.parse_obj(load_toml(file_names))
except (FileNotFoundError) as e:
if isinstance(file_names, list):
if len(file_names) == 1:
logger.warning("%s could not be loaded: %s", file_names[0], e)
else:
logger.warning(
"%s could not be loaded: %s",
" or ".join([str(x) for x in file_names]),
e,
)
else:
logger.warning("%s could not be loaded: %s", file_names, e)
logger.warning(
"Application config could not be loaded from files: %s due to error: %s",
filenames_as_str,
e,
)
# If no path is specified Pydantic will attempt to read settings from
# the environment. Default values will still be used if the matching
# environment variable is not set.
try:
logger.info(
"Attempting to load application config from environment variables"
)
return class_name()
except ValidationError as exc:
logger.error("ValidationError: %s", exc)
logger.error(
"Application config could not be loaded from environment variables due to error: %s",
exc,
)
# If FidesConfig is missing any required values Pydantic will throw
# an ImportError. This means the config has not been correctly specified
# so we can throw the missing config error.
Expand Down

0 comments on commit 6083c7f

Please sign in to comment.