Skip to content

Commit

Permalink
Improve errors with invalid yaml files (#2589)
Browse files Browse the repository at this point in the history
Fixes: #1718
  • Loading branch information
ssbarnea committed Oct 10, 2022
1 parent 0e672f0 commit 73733fd
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/ansiblelint/utils.py
Expand Up @@ -702,7 +702,7 @@ def get_action_tasks(data: AnsibleBaseYAMLObject, file: Lintable) -> list[Any]:
@lru_cache(maxsize=None)
def parse_yaml_linenumbers( # noqa: max-complexity: 12
lintable: Lintable,
) -> AnsibleBaseYAMLObject | AnsibleBaseYAMLObject:
) -> AnsibleBaseYAMLObject:
"""Parse yaml as ansible.utils.parse_yaml but with linenumbers.
The line numbers are stored in each node's LINE_NUMBER_KEY key.
Expand Down Expand Up @@ -746,7 +746,11 @@ def construct_mapping(
if data is None:
break
result.append(data)
except (yaml.parser.ParserError, yaml.scanner.ScannerError) as exc:
except (
yaml.parser.ParserError,
yaml.scanner.ScannerError,
yaml.constructor.ConstructorError,
) as exc:
raise RuntimeError("Failed to load YAML file") from exc

if len(result) == 0:
Expand Down

0 comments on commit 73733fd

Please sign in to comment.