changeset 46:346c702f63db

better error message
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 27 Mar 2012 12:26:58 -0700
parents bb5f4eeb56c5
children 7abea9a6fa16
files configuration/config.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/configuration/config.py	Tue Mar 27 12:16:43 2012 -0700
+++ b/configuration/config.py	Tue Mar 27 12:26:58 2012 -0700
@@ -32,6 +32,9 @@
 class ConfigurationProviderException(Exception):
     """exception raised when a configuration provider is missing, etc"""
 
+class TypeCastException(Exception):
+    """exception raised when a configuration item cannot be coerced to a type"""
+
 ### configuration providers for serialization/deserialization
 
 configuration_providers = []
@@ -204,7 +207,10 @@
         for key, value in config.items():
             _type = self.options[key].get('type')
             if _type is not None:
-                config[key] = _type(value)
+                try:
+                    config[key] = _type(value)
+                except BaseException, e:
+                    raise TypeCastException("Could not coerce %s, %s, to type %s: %s" % (key, value, _type.__name__, e))
 
         return config