diff options
Diffstat (limited to 'heatclient/common/template_format.py')
-rw-r--r-- | heatclient/common/template_format.py | 14 |
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 = {} |