Skip to content

Commit

Permalink
Detect ScannerError while searching for skipped rules (#2619)
Browse files Browse the repository at this point in the history
* Do not crash when encountering ScannerError while searching for skipped rules.

* Log exception

Co-authored-by: Sorin Sbarnea <[email protected]>
  • Loading branch information
felixfontein and ssbarnea authored Oct 26, 2022
1 parent c8a6871 commit 9be4903
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ansiblelint/skip_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 [
Expand Down

0 comments on commit 9be4903

Please sign in to comment.