Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/ansible_core-2.17.0.dev0-py3.8.egg/ansible/errors/yaml_strings.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.3.2, created at 2023-11-30 06:38 +0000

1# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> 

2# 

3# This file is part of Ansible 

4# 

5# Ansible is free software: you can redistribute it and/or modify 

6# it under the terms of the GNU General Public License as published by 

7# the Free Software Foundation, either version 3 of the License, or 

8# (at your option) any later version. 

9# 

10# Ansible is distributed in the hope that it will be useful, 

11# but WITHOUT ANY WARRANTY; without even the implied warranty of 

12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

13# GNU General Public License for more details. 

14# 

15# You should have received a copy of the GNU General Public License 

16# along with Ansible. If not, see <http://www.gnu.org/licenses/>. 

17 

18from __future__ import annotations 

19 

20__all__ = [ 

21 'YAML_SYNTAX_ERROR', 

22 'YAML_POSITION_DETAILS', 

23 'YAML_COMMON_DICT_ERROR', 

24 'YAML_COMMON_UNQUOTED_VARIABLE_ERROR', 

25 'YAML_COMMON_UNQUOTED_COLON_ERROR', 

26 'YAML_COMMON_PARTIALLY_QUOTED_LINE_ERROR', 

27 'YAML_COMMON_UNBALANCED_QUOTES_ERROR', 

28] 

29 

30YAML_SYNTAX_ERROR = """\ 

31Syntax Error while loading YAML. 

32 %s""" 

33 

34YAML_POSITION_DETAILS = """\ 

35The error appears to be in '%s': line %s, column %s, but may 

36be elsewhere in the file depending on the exact syntax problem. 

37""" 

38 

39YAML_COMMON_DICT_ERROR = """\ 

40This one looks easy to fix. YAML thought it was looking for the start of a 

41hash/dictionary and was confused to see a second "{". Most likely this was 

42meant to be an ansible template evaluation instead, so we have to give the 

43parser a small hint that we wanted a string instead. The solution here is to 

44just quote the entire value. 

45 

46For instance, if the original line was: 

47 

48 app_path: {{ base_path }}/foo 

49 

50It should be written as: 

51 

52 app_path: "{{ base_path }}/foo" 

53""" 

54 

55YAML_COMMON_UNQUOTED_VARIABLE_ERROR = """\ 

56We could be wrong, but this one looks like it might be an issue with 

57missing quotes. Always quote template expression brackets when they 

58start a value. For instance: 

59 

60 with_items: 

61 - {{ foo }} 

62 

63Should be written as: 

64 

65 with_items: 

66 - "{{ foo }}" 

67""" 

68 

69YAML_COMMON_UNQUOTED_COLON_ERROR = """\ 

70This one looks easy to fix. There seems to be an extra unquoted colon in the line 

71and this is confusing the parser. It was only expecting to find one free 

72colon. The solution is just add some quotes around the colon, or quote the 

73entire line after the first colon. 

74 

75For instance, if the original line was: 

76 

77 copy: src=file.txt dest=/path/filename:with_colon.txt 

78 

79It can be written as: 

80 

81 copy: src=file.txt dest='/path/filename:with_colon.txt' 

82 

83Or: 

84 

85 copy: 'src=file.txt dest=/path/filename:with_colon.txt' 

86""" 

87 

88YAML_COMMON_PARTIALLY_QUOTED_LINE_ERROR = """\ 

89This one looks easy to fix. It seems that there is a value started 

90with a quote, and the YAML parser is expecting to see the line ended 

91with the same kind of quote. For instance: 

92 

93 when: "ok" in result.stdout 

94 

95Could be written as: 

96 

97 when: '"ok" in result.stdout' 

98 

99Or equivalently: 

100 

101 when: "'ok' in result.stdout" 

102""" 

103 

104YAML_COMMON_UNBALANCED_QUOTES_ERROR = """\ 

105We could be wrong, but this one looks like it might be an issue with 

106unbalanced quotes. If starting a value with a quote, make sure the 

107line ends with the same set of quotes. For instance this arbitrary 

108example: 

109 

110 foo: "bad" "wolf" 

111 

112Could be written as: 

113 

114 foo: '"bad" "wolf"' 

115""" 

116 

117YAML_COMMON_LEADING_TAB_ERROR = """\ 

118There appears to be a tab character at the start of the line. 

119 

120YAML does not use tabs for formatting. Tabs should be replaced with spaces. 

121 

122For example: 

123 - name: update tooling 

124 vars: 

125 version: 1.2.3 

126# ^--- there is a tab there. 

127 

128Should be written as: 

129 - name: update tooling 

130 vars: 

131 version: 1.2.3 

132# ^--- all spaces here. 

133""" 

134 

135YAML_AND_SHORTHAND_ERROR = """\ 

136There appears to be both 'k=v' shorthand syntax and YAML in this task. \ 

137Only one syntax may be used. 

138"""