Merge "Report more YAML syntax errors"

This commit is contained in:
Zuul 2021-11-16 19:19:56 +00:00 committed by Gerrit Code Review
commit 9b1f2838d7
2 changed files with 25 additions and 0 deletions

View File

@ -1708,6 +1708,25 @@ class TestInRepoConfig(ZuulTestCase):
self.assertIn('job_not_a_dict', A.messages[0],
"A should list the bad key")
def test_yaml_dict_error2(self):
in_repo_conf = textwrap.dedent(
"""
- foo: {{ not_a_dict }}
""")
file_dict = {'.zuul.yaml': in_repo_conf}
A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A',
files=file_dict)
A.addApproval('Code-Review', 2)
self.fake_gerrit.addEvent(A.addApproval('Approved', 1))
self.waitUntilSettled()
self.assertEqual(A.data['status'], 'NEW')
self.assertEqual(A.reported, 1,
"A should report failure")
self.assertIn('while constructing a mapping', A.messages[0],
"A should have a syntax error reported")
def test_yaml_duplicate_key_error(self):
in_repo_conf = textwrap.dedent(
"""

View File

@ -347,6 +347,12 @@ class ZuulSafeLoader(yaml.EncryptedLoader):
if k.value == '<<':
continue
if not isinstance(k.value, collections.abc.Hashable):
# This happens with "foo: {{ bar }}"
# This will raise an error in the superclass
# construct_mapping below; ignore it for now.
continue
if k.value in keys:
mark = model.ZuulMark(node.start_mark, node.end_mark,
self.zuul_stream)