Skip to content

Commit

Permalink
Continue on template decode errors (#3605)
Browse files Browse the repository at this point in the history
* Continue on template decode errors
  • Loading branch information
kddejong authored Aug 16, 2024
1 parent 68ac3a6 commit 2ab6759
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/cfnlint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,9 @@ def _validate_filenames(self, filenames: Sequence[str | None]) -> Iterator[Match
"E0000".startswith(x) for x in self.config.ignore_checks
):
matches = [match for match in matches if match.rule.id != "E0000"]
if matches:
yield from iter(matches)
return
else:
yield from iter(matches)
return

yield from iter(matches)
continue
yield from self.validate_template(filename, template) # type: ignore[arg-type] # noqa: E501

def validate_template(
Expand Down
55 changes: 55 additions & 0 deletions test/unit/module/runner/test_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""

import pytest

from cfnlint.config import ConfigMixIn
from cfnlint.runner import Runner


@pytest.mark.parametrize(
"name,config,expected_count",
[
(
"Test decode errors with multiple files",
ConfigMixIn(
cli_args=[
"--template",
"test/fixtures/templates/bad/duplicate.yaml",
"test/fixtures/templates/bad/duplicate.json",
]
),
6,
),
(
"Test decode errors with E0000 being ignored",
ConfigMixIn(
cli_args=[
"--template",
"test/fixtures/templates/bad/core/parse_invalid_map.yaml",
"--ignore-bad-template",
]
),
0,
),
(
"Test decode return E0000 errors",
ConfigMixIn(
cli_args=[
"--template",
"test/fixtures/templates/bad/core/parse_invalid_map.yaml",
]
),
1,
),
],
)
def test_run(name, config, expected_count):

runner = Runner(config)

errs = list(runner.run())

assert len(errs) == expected_count, f"{name}: {errs}"

0 comments on commit 2ab6759

Please sign in to comment.