mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-10-25 05:23:58 -07:00
Add error info if tabs are found in the yaml (#18343)
If a yaml file fails to load because of tabs being used for formatting, detect that and show a error message with more details.
This commit is contained in:
parent
e8e09f3df6
commit
51e3ef89a9
4 changed files with 41 additions and 1 deletions
|
|
@ -37,8 +37,10 @@ from units.mock.yaml_helper import YamlTestUtils
|
|||
|
||||
try:
|
||||
from _yaml import ParserError
|
||||
from _yaml import ScannerError
|
||||
except ImportError:
|
||||
from yaml.parser import ParserError
|
||||
from yaml.scanner import ScannerError
|
||||
|
||||
|
||||
class NameStringIO(StringIO):
|
||||
|
|
@ -145,6 +147,11 @@ class TestAnsibleLoaderBasic(unittest.TestCase):
|
|||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
self.assertRaises(ParserError, loader.get_single_data)
|
||||
|
||||
def test_tab_error(self):
|
||||
stream = StringIO(u"""---\nhosts: localhost\nvars:\n foo: bar\n\tblip: baz""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
self.assertRaises(ScannerError, loader.get_single_data)
|
||||
|
||||
def test_front_matter(self):
|
||||
stream = StringIO(u"""---\nfoo: bar""")
|
||||
loader = AnsibleLoader(stream, 'myfile.yml')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue