Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include resource title in required attr exception #597

Merged
merged 4 commits into from
Nov 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ def __init__(self, *args, **kwargs):
instance = ExtendedInstance('ec2instance', attribute='value')
self.assertEqual(instance.attribute, 'value')

def test_required_title_error(self):
with self.assertRaisesRegexp(ValueError, "title:"):
t = Template()
t.add_resource(Instance('ec2instance'))
t.to_json()


def call_correct(x):
return x
Expand Down
8 changes: 6 additions & 2 deletions troposphere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ def JSONrepr(self):
for k, (_, required) in self.props.items():
if required and k not in self.properties:
rtype = getattr(self, 'resource_type', "<unknown type>")
raise ValueError(
"Resource %s required in type %s" % (k, rtype))
title = getattr(self, 'title')
msg = "Resource %s required in type %s" % (k, rtype)
if title:
msg += " (title: %s)" % title
raise ValueError(msg)

self.validate()
# Mainly used to not have an empty "Properties".
if self.properties:
Expand Down