From 3c0d142d0fe7645c448f143e73bd74ca8ff403a8 Mon Sep 17 00:00:00 2001 From: Sandy Walsh Date: Tue, 7 Oct 2014 11:53:53 -0700 Subject: [PATCH] Better error reporting for bad trait definitions. In the case someone does destination_trait: source_trait instead of destination_trait: fields: source_trait it will now get a proper error message. Change-Id: Ia22f58b6443714c2a407c7a3f94ed24f437efc1c --- stackdistiller/distiller.py | 8 +++++++- tests/test_distiller.py | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/stackdistiller/distiller.py b/stackdistiller/distiller.py index d834ef0..b8b6c20 100644 --- a/stackdistiller/distiller.py +++ b/stackdistiller/distiller.py @@ -105,7 +105,13 @@ class TraitDefinition(object): self.cfg = trait_cfg self.name = name - type_name = trait_cfg.get('type', 'text') + type_name = None + try: + type_name = trait_cfg.get('type', 'text') + except AttributeError as e: + raise EventDefinitionException( + "Unable to get type for '%s'" % trait_cfg, + self.cfg) if 'plugin' in trait_cfg: plugin_cfg = trait_cfg['plugin'] diff --git a/tests/test_distiller.py b/tests/test_distiller.py index 66d6729..64fd87d 100644 --- a/tests/test_distiller.py +++ b/tests/test_distiller.py @@ -143,6 +143,13 @@ class TestTraitDefinition(DistillerTestBase): self.fake_plugin_map = dict(test=self.test_plugin_class, nothing=self.nothing_plugin_class) + def test_bad_field_definition(self): + self.assertRaises(distiller.EventDefinitionException, + distiller.TraitDefinition, + 'test_trait', + "foo", + self.fake_plugin_map) + def test_to_trait_with_plugin(self): cfg = dict(type='text', fields=['payload.instance_id', 'payload.instance_uuid'],