Skip to content

Commit b6fe397

Browse files
authored
config: Report if 'rules' is not a dict
In the current version, the error message states `TypeError: 'NoneType' object is not iterable` when the 'rules' in the config file is not a dict (gh-274.) It would be helpful to improve the error message. Additionally, it is for consistency, as other elements (`ignore`, `locale`, etc.) have similar error checks.
1 parent 2ec2d7a commit b6fe397

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

tests/test_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,10 @@ class Rule:
197197
{'multiple': ['item4']})
198198

199199
def test_invalid_rule(self):
200+
with self.assertRaisesRegex(
201+
config.YamlLintConfigError,
202+
'invalid config: rules should be a dict'):
203+
config.YamlLintConfig('rules:\n')
200204
with self.assertRaisesRegex(
201205
config.YamlLintConfigError,
202206
'invalid config: rule "colons": should be either '

yamllint/config.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ def parse(self, raw_content):
8282
raise YamlLintConfigError('invalid config: not a dict')
8383

8484
self.rules = conf.get('rules', {})
85+
if not isinstance(self.rules, dict):
86+
raise YamlLintConfigError('invalid config: rules should be a dict')
8587
for rule in self.rules:
8688
if self.rules[rule] == 'enable':
8789
self.rules[rule] = {}

0 commit comments

Comments
 (0)