Make Fn::Join give a better error message

When something goes wrong at the moment users are left staring hard
at their template trying to figure out whats wrong. We can make this a
lot easier by showing them the failed object.

Change-Id: If87447b7e160591505a68d857e8ef1751aac3723
This commit is contained in:
Angus Salkeld 2014-08-18 13:27:44 +10:00
parent c59f659b10
commit 5da90ebee2
2 changed files with 10 additions and 1 deletions

View File

@ -302,7 +302,8 @@ class Join(function.Function):
if s is None:
return ''
if not isinstance(s, basestring):
raise TypeError(_('Items to join must be strings'))
raise TypeError(
_('Items to join must be strings %s') % (repr(s)[:200]))
return s
return delim.join(ensure_string(s) for s in strings)

View File

@ -852,6 +852,14 @@ class ResolveDataTest(HeatTestCase):
[' ', ['foo', 'bar']]}, 'baz']]}
self.assertEqual('foo bar\nbaz', self.resolve(raw))
def test_join_not_string(self):
snippet = {'Fn::Join': ['\n', [{'Fn::Join':
[' ', ['foo', 45]]}, 'baz']]}
error = self.assertRaises(TypeError,
self.resolve,
snippet)
self.assertIn('45', six.text_type(error))
def test_base64_replace(self):
raw = {'Fn::Base64': {'Fn::Replace': [
{'foo': 'bar'}, 'Meet at the foo']}}