Skip to content

Commit bba21dc

Browse files
authored
Don't fail when ignore templates is empty or not findable (#3900)
1 parent 3ae3941 commit bba21dc

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

src/cfnlint/config.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -785,9 +785,11 @@ def _ignore_templates(self):
785785
if isinstance(filenames, str):
786786
filenames = [filenames]
787787

788-
return self._glob_filenames(filenames)
788+
return self._glob_filenames(filenames, False)
789789

790-
def _glob_filenames(self, filenames: Sequence[str]) -> list[str]:
790+
def _glob_filenames(
791+
self, filenames: Sequence[str], raise_exception: bool = True
792+
) -> list[str]:
791793
# handle different shells and Config files
792794
# some shells don't expand * and configparser won't expand wildcards
793795
all_filenames = []
@@ -796,7 +798,8 @@ def _glob_filenames(self, filenames: Sequence[str]) -> list[str]:
796798
add_filenames = glob.glob(filename, recursive=True)
797799

798800
if not add_filenames and not self.ignore_bad_template:
799-
raise ValueError(f"{filename} could not be processed by glob.glob")
801+
if raise_exception:
802+
raise ValueError(f"{filename} could not be processed by glob.glob")
800803

801804
all_filenames.extend(add_filenames)
802805

test/unit/module/config/test_config_mixin.py

+22
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,28 @@ def test_config_expand_ignore_templates(self, yaml_mock):
247247
)
248248
self.assertEqual(len(config.templates), 3)
249249

250+
@patch("cfnlint.config.ConfigFileArgs._read_config", create=True)
251+
def test_config_expand_and_ignore_templates_with_bad_path(self, yaml_mock):
252+
"""Test ignore templates"""
253+
254+
yaml_mock.side_effect = [
255+
{
256+
"templates": ["test/fixtures/templates/bad/resources/iam/*.yaml"],
257+
"ignore_templates": [
258+
"dne/fixtures/templates/bad/resources/iam/resource_*.yaml"
259+
],
260+
},
261+
{},
262+
]
263+
config = cfnlint.config.ConfigMixIn([])
264+
265+
# test defaults
266+
self.assertIn(
267+
str(Path("test/fixtures/templates/bad/resources/iam/resource_policy.yaml")),
268+
config.templates,
269+
)
270+
self.assertEqual(len(config.templates), 4)
271+
250272
@patch("cfnlint.config.ConfigFileArgs._read_config", create=True)
251273
def test_config_merge(self, yaml_mock):
252274
"""Test merging lists"""

0 commit comments

Comments
 (0)