Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
ansible
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
ansible
Commits
c692de6b
Commit
c692de6b
authored
Feb 09, 2013
by
Michael DeHaan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup YAML parse error warning code a tiny amount.
parent
5c382487
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
19 deletions
+26
-19
lib/ansible/utils/__init__.py
+26
-19
No files found.
lib/ansible/utils/__init__.py
View file @
c692de6b
...
...
@@ -236,6 +236,31 @@ def parse_yaml(data):
''' convert a yaml string to a data structure '''
return
yaml
.
load
(
data
)
def
process_yaml_error
(
exc
,
data
,
path
=
None
):
if
hasattr
(
exc
,
'problem_mark'
):
mark
=
exc
.
problem_mark
if
mark
.
line
-
1
>=
0
:
before_probline
=
data
.
split
(
"
\n
"
)[
mark
.
line
-
1
]
else
:
before_probline
=
''
probline
=
data
.
split
(
"
\n
"
)[
mark
.
line
]
arrow
=
" "
*
mark
.
column
+
"^"
msg
=
"""Syntax Error while loading YAML script,
%
s
Note: The error may actually appear before this position: line
%
s, column
%
s
%
s
%
s
%
s"""
%
(
path
,
mark
.
line
+
1
,
mark
.
column
+
1
,
before_probline
,
probline
,
arrow
)
else
:
# No problem markers means we have to throw a generic
# "stuff messed up" type message. Sry bud.
if
path
:
msg
=
"Could not parse YAML. Check over
%
s again."
%
path
else
:
msg
=
"Could not parse YAML."
raise
errors
.
AnsibleYAMLValidationFailed
(
msg
)
def
parse_yaml_from_file
(
path
):
''' convert a yaml file to a data structure '''
...
...
@@ -245,25 +270,7 @@ def parse_yaml_from_file(path):
except
IOError
:
raise
errors
.
AnsibleError
(
"file not found:
%
s"
%
path
)
except
yaml
.
YAMLError
,
exc
:
if
hasattr
(
exc
,
'problem_mark'
):
mark
=
exc
.
problem_mark
if
mark
.
line
-
1
>=
0
:
before_probline
=
data
.
split
(
"
\n
"
)[
mark
.
line
-
1
]
else
:
before_probline
=
''
probline
=
data
.
split
(
"
\n
"
)[
mark
.
line
]
arrow
=
" "
*
mark
.
column
+
"^"
msg
=
"""Syntax Error while loading YAML script,
%
s
Note: The error may actually appear before this position: line
%
s, column
%
s
%
s
%
s
%
s"""
%
(
path
,
mark
.
line
+
1
,
mark
.
column
+
1
,
before_probline
,
probline
,
arrow
)
else
:
# No problem markers means we have to throw a generic
# "stuff messed up" type message. Sry bud.
msg
=
"Could not parse YAML. Check over
%
s again."
%
path
raise
errors
.
AnsibleYAMLValidationFailed
(
msg
)
process_yaml_error
(
exc
,
data
,
path
)
def
parse_kv
(
args
):
''' convert a string of key/value items to a dict '''
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment