Skip to content

Commit

Permalink
Added error handling when loading catalogs
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-baillargeon committed Feb 28, 2024
1 parent c490e18 commit 1461c6d
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from asyncio import run
from typing import TYPE_CHECKING, Mapping

from yaml import CSafeLoader, dump, load
from yaml import CSafeLoader, YAMLError, dump, load

from ansible_collections.arista.avd.plugins.plugin_utils.errors import AristaAvdError
from ansible_collections.arista.avd.plugins.plugin_utils.merge import merge_catalogs
Expand Down Expand Up @@ -141,9 +141,13 @@ def load_custom_catalogs(catalog_files: list[Path]) -> dict:
"""
catalog_list = []
for file in catalog_files:
with file.open("r", encoding="UTF-8") as fd:
catalog = load(fd, Loader=CSafeLoader)
catalog_list.append(catalog)
try:
with file.open("r", encoding="UTF-8") as fd:
catalog = load(fd, Loader=CSafeLoader)
catalog_list.append(catalog)
except (OSError, YAMLError) as error:
msg = f"Failed to load the custom ANTA catalog from {file}: {error!s}"
raise AristaAvdError(msg) from error

return merge_catalogs(*catalog_list) if catalog_list else {}

Expand Down

0 comments on commit 1461c6d

Please sign in to comment.