[imp] raise more useful error message when a context is invalid
authorniv-openerp <nicolas.vanhoren@openerp.com>
Fri, 14 Oct 2011 12:33:07 +0000 (14:33 +0200)
committerniv-openerp <nicolas.vanhoren@openerp.com>
Fri, 14 Oct 2011 12:33:07 +0000 (14:33 +0200)
bzr revid: nicolas.vanhoren@openerp.com-20111014123307-xf7flm6er0puapew

addons/web/common/nonliterals.py

index 986ca36..42dbe9c 100644 (file)
@@ -131,7 +131,10 @@ class Domain(BaseDomain):
         ctx = self.session.evaluation_context(context)
         if self.own:
             ctx.update(self.own)
-        return eval(self.get_domain_string(), SuperDict(ctx))
+        try:
+            return eval(self.get_domain_string(), SuperDict(ctx))
+        except NameError as e:
+            raise ValueError('Error during evaluation of this domain: "%s", message: "%s"' % (self.get_domain_string(), e.message))
 
 class Context(BaseContext):
     def __init__(self, session, context_string=None, key=None):
@@ -176,7 +179,10 @@ class Context(BaseContext):
         ctx = self.session.evaluation_context(context)
         if self.own:
             ctx.update(self.own)
-        return eval(self.get_context_string(), SuperDict(ctx))
+        try:
+            return eval(self.get_context_string(), SuperDict(ctx))
+        except NameError as e:
+            raise ValueError('Error during evaluation of this context: "%s", message: "%s"' % (self.get_context_string(), e.message))
 
 class SuperDict(dict):
     def __getattr__(self, name):