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:
Adrian Likins
2016-11-08 11:43:08 -05:00
committed by GitHub
parent e8e09f3df6
commit 51e3ef89a9
4 changed files with 41 additions and 1 deletions

View File

@@ -24,7 +24,8 @@ from ansible.errors.yaml_strings import ( YAML_POSITION_DETAILS,
YAML_COMMON_DICT_ERROR,
YAML_COMMON_UNQUOTED_COLON_ERROR,
YAML_COMMON_PARTIALLY_QUOTED_LINE_ERROR,
YAML_COMMON_UNBALANCED_QUOTES_ERROR )
YAML_COMMON_UNBALANCED_QUOTES_ERROR,
YAML_COMMON_LEADING_TAB_ERROR)
from ansible.module_utils._text import to_native, to_text
@@ -111,6 +112,9 @@ class AnsibleError(Exception):
#header_line = ("=" * 73)
error_message += "\nThe offending line appears to be:\n\n%s\n%s\n%s\n" % (prev_line.rstrip(), target_line.rstrip(), arrow_line)
# TODO: There may be cases where there is a valid tab in a line that has other errors.
if '\t' in target_line:
error_message += YAML_COMMON_LEADING_TAB_ERROR
# common error/remediation checking here:
# check for unquoted vars starting lines
if ('{{' in target_line and '}}' in target_line) and ('"{{' not in target_line or "'{{" not in target_line):

View File

@@ -116,3 +116,20 @@ Could be written as:
foo: '"bad" "wolf"'
"""
YAML_COMMON_LEADING_TAB_ERROR = """\
There appears to be a tab character at the start of the line.
YAML does not use tabs for formatting. Tabs should be replaced with spaces.
For example:
- name: update tooling
vars:
version: 1.2.3
# ^--- there is a tab there.
Should be written as:
- name: update tooling
vars:
version: 1.2.3
# ^--- all spaces here.
"""