summaryrefslogtreecommitdiff
path: root/heatclient/common/template_format.py
diff options
context:
space:
mode:
authorPeter Razumovsky <prazumovsky@mirantis.com>2015-10-08 17:22:59 +0300
committerPeter Razumovsky <prazumovsky@mirantis.com>2015-10-09 09:23:33 +0300
commit54a1715e348720ab31b5d2e38035bf429471cdbe (patch)
treea1796cb077dd625b3554e8001c4944f3a58e0135 /heatclient/common/template_format.py
parent6c86efc1a39792cb08e18ff6bd5ca3af0c1739ed (diff)
downloadpython-heatclient-54a1715e348720ab31b5d2e38035bf429471cdbe.tar.gz
Add option for detailed template error
Add option detailed_template_error for informative error during template and environment parsing. yaml.SafeLoader returns error with template snippet where error has been occurred instead of CSafeLoader. But CSafeLoader is faster. So, if user wants to get more informative error, use slower but more detailed SafeLoader for yaml loading. Change-Id: Ied0a573a00eb5f564dea0c636da1301de5de9ea7 Closes-bug: #1496361
Diffstat (limited to 'heatclient/common/template_format.py')
-rw-r--r--heatclient/common/template_format.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/heatclient/common/template_format.py b/heatclient/common/template_format.py
index 2f4a91a..1636ebb 100644
--- a/heatclient/common/template_format.py
+++ b/heatclient/common/template_format.py
@@ -40,18 +40,24 @@ yaml_loader.add_constructor(u'tag:yaml.org,2002:timestamp',
def parse(tmpl_str):
- '''Takes a string and returns a dict containing the parsed structure.
+ """Takes a string and returns a dict containing the parsed structure.
This includes determination of whether the string is using the
JSON or YAML format.
- '''
+ """
if tmpl_str.startswith('{'):
tpl = json.loads(tmpl_str)
else:
try:
tpl = yaml.load(tmpl_str, Loader=yaml_loader)
- except yaml.YAMLError as yea:
- raise ValueError(yea)
+ except yaml.YAMLError:
+ # NOTE(prazumovsky): we need to return more informative error for
+ # user, so use SafeLoader, which return error message with template
+ # snippet where error has been occurred.
+ try:
+ tpl = yaml.load(tmpl_str, Loader=yaml.SafeLoader)
+ except yaml.YAMLError as yea:
+ raise ValueError(yea)
else:
if tpl is None:
tpl = {}