Merge "Pass errors from *_format.parse() to the caller"

This commit is contained in:
Jenkins 2013-10-15 16:36:19 +00:00 committed by Gerrit Code Review
commit 3dc2ce01de
2 changed files with 18 additions and 3 deletions

View File

@ -71,9 +71,10 @@ class InstantiationData(object):
return environment_format.parse(data)
else:
return template_format.parse(data)
except ValueError:
err_reason = _("%s not in valid format") % data_type
raise exc.HTTPBadRequest(err_reason)
except ValueError as parse_ex:
mdict = {'type': data_type, 'error': parse_ex}
msg = _("%(type)s not in valid format: %(error)s") % mdict
raise exc.HTTPBadRequest(msg)
def stack_name(self):
"""

View File

@ -71,6 +71,20 @@ class InstantiationDataTest(HeatTestCase):
stacks.InstantiationData.format_parse,
'!@#$%^&not json', 'Garbage')
def test_format_parse_invalid_message(self):
# make sure the parser error gets through to the caller.
bad_temp = '''
parameters:
KeyName:
type: string
description: bla
'''
parse_ex = self.assertRaises(webob.exc.HTTPBadRequest,
stacks.InstantiationData.format_parse,
bad_temp, 'foo')
self.assertIn('line 3, column 3', str(parse_ex))
def test_stack_name(self):
body = {'stack_name': 'wibble'}
data = stacks.InstantiationData(body)