Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect ScannerError while searching for skipped rules #2619

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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