From 73733fd310098d4206d09dbeb9e4616f4d4dc6ba Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 10 Oct 2022 22:26:51 +0100 Subject: [PATCH] Improve errors with invalid yaml files (#2589) Fixes: #1718 --- src/ansiblelint/utils.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/ansiblelint/utils.py b/src/ansiblelint/utils.py index 0569666d9e..5042749ebd 100644 --- a/src/ansiblelint/utils.py +++ b/src/ansiblelint/utils.py @@ -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. @@ -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: