Skip to content

Commit

Permalink
fix(general): add try except to loads file (#6668)
Browse files Browse the repository at this point in the history
* .

* .

* .

* .
  • Loading branch information
lirshindalman authored Aug 19, 2024
1 parent 28e1bae commit 14d4304
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 6 additions & 3 deletions checkov/ansible/graph_builder/local_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,11 @@ def get_files_definitions(root_folder: str | Path) -> dict[str | Path, dict[str,
file_paths = get_scannable_file_paths(root_folder=root_folder)

for file_path in file_paths:
result = parse_file(f=file_path)
if result is not None:
definitions[file_path] = result[0]
try:
result = parse_file(f=file_path)
if result is not None:
definitions[file_path] = result[0]
except Exception as err:
logging.warning(f'fail to pars file {file_path}, {err}')

return definitions
10 changes: 6 additions & 4 deletions checkov/common/parsers/yaml/loader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import logging
from collections.abc import Hashable
from pathlib import Path
from typing import Any, TYPE_CHECKING
Expand All @@ -17,13 +18,14 @@ def loads(content: str) -> list[dict[str, Any]]:
"""
Load the given YAML string
"""

template = list(yaml.load_all(content, Loader=SafeLineLoader))

try:
template = list(yaml.load_all(content, Loader=SafeLineLoader))
except Exception as e:
logging.warning(f'Fail to load yaml content, {e}')
template = [None]
# Convert an empty file to an empty dict
if template is None:
template = {}

return template


Expand Down

0 comments on commit 14d4304

Please sign in to comment.