diff options
author | Peter Razumovsky <prazumovsky@mirantis.com> | 2015-10-08 17:22:59 +0300 |
---|---|---|
committer | Peter Razumovsky <prazumovsky@mirantis.com> | 2015-10-09 09:23:33 +0300 |
commit | 54a1715e348720ab31b5d2e38035bf429471cdbe (patch) | |
tree | a1796cb077dd625b3554e8001c4944f3a58e0135 /heatclient/common/environment_format.py | |
parent | 6c86efc1a39792cb08e18ff6bd5ca3af0c1739ed (diff) | |
download | python-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/environment_format.py')
-rw-r--r-- | heatclient/common/environment_format.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/heatclient/common/environment_format.py b/heatclient/common/environment_format.py index 0b876b6..5c29aad 100644 --- a/heatclient/common/environment_format.py +++ b/heatclient/common/environment_format.py @@ -21,15 +21,21 @@ SECTIONS = (PARAMETER_DEFAULTS, PARAMETERS, RESOURCE_REGISTRY) = \ def parse(env_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 YAML format. - ''' + """ try: env = yaml.load(env_str, Loader=template_format.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: + env = yaml.load(env_str, Loader=yaml.SafeLoader) + except yaml.YAMLError as yea: + raise ValueError(yea) else: if env is None: env = {} |