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

Conversation

phobologic
Copy link
Member

Based on helping with this issue:
http://stackoverflow.com/questions/40118794/dynamically-create-n-number-of-ec2-instances-with-troposphere/40122167?noredirect=1#comment67537659_40122167

Now, if a resource is missing a required attribute, and that resource
has a title, we'll include it in the exception.

ValueError: Resource ImageId required in type AWS::EC2::Instance

vs

ValueError: Resource ImageId required in type AWS::EC2::Instance (title: MyInstance)

Based on helping with this issue:
http://stackoverflow.com/questions/40118794/dynamically-create-n-number-of-ec2-instances-with-troposphere/40122167?noredirect=1#comment67537659_40122167

Now, if a resource is missing a required attribute, and that resource
has a title, we'll include it in the exception.

ValueError: Resource ImageId required in type AWS::EC2::Instance

vs

ValueError: Resource ImageId required in type AWS::EC2::Instance (title: MyInstance)
@markpeek
Copy link
Member

Looks good. Perhaps add a test like this?

diff --git a/tests/test_basic.py b/tests/test_basic.py
index c904d58..cd6c9d4 100644
--- a/tests/test_basic.py
+++ b/tests/test_basic.py
@@ -26,6 +26,12 @@ class TestBasic(unittest.TestCase):
     def test_goodrequired(self):
         Instance('ec2instance', ImageId="ami-xxxx", InstanceType="m1.small")

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

         class ExtendedInstance(Instance):

@phobologic
Copy link
Member Author

Good call, done.

@markpeek markpeek merged commit 7e6899a into master Nov 15, 2016
@markpeek markpeek deleted the better_required_attribute_error branch December 30, 2021 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants