From 9be49030c3ba9894071ab865d9d25d45d196058f Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 26 Oct 2022 23:24:27 +0200 Subject: [PATCH] Detect ScannerError while searching for skipped rules (#2619) * Do not crash when encountering ScannerError while searching for skipped rules. * Log exception Co-authored-by: Sorin Sbarnea --- src/ansiblelint/skip_utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ansiblelint/skip_utils.py b/src/ansiblelint/skip_utils.py index cdfff562c9..548163dd4d 100644 --- a/src/ansiblelint/skip_utils.py +++ b/src/ansiblelint/skip_utils.py @@ -30,6 +30,7 @@ # Module 'ruamel.yaml' does not explicitly export attribute 'YAML'; implicit reexport disabled from ruamel.yaml import YAML from ruamel.yaml.composer import ComposerError +from ruamel.yaml.scanner import ScannerError from ruamel.yaml.tokens import CommentToken from ansiblelint.config import used_old_tags @@ -124,7 +125,14 @@ def _append_skipped_rules( # noqa: max-complexity: 12 pyyaml_data: AnsibleBaseYAMLObject, lintable: Lintable ) -> AnsibleBaseYAMLObject | None: # parse file text using 2nd parser library - ruamel_data = load_data(lintable.content) + try: + ruamel_data = load_data(lintable.content) + except ScannerError as exc: + _logger.debug( + "Ignored loading skipped rules from file %s due to: %s", lintable, exc + ) + # For unparsable file types, we return empty skip lists + return None skipped_rules = _get_rule_skips_from_yaml(ruamel_data, lintable) if lintable.kind in [