On 01.08.2011 16:13, Adam Young wrote:
> OTOH, if the env is something that can change, then we should not
> require it for the validate call.  Is it possible to validate without an
> env?
I looked at other exceptions thrown and now pass self.cli_name if it
exists and self.name otherwise -- this is what other validation checks
were doing without relying on an environment. If parameter has
self.cli_name then user would most likely to see it as exception is
producing an error message and not used for anything else.

diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index e1c0b09..e26c33e 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -725,10 +725,10 @@ class Param(ReadOnly):
         """
         if value is None:
             if self.required:
-                if context == 'cli':
-                    raise RequirementError(name=self.cli_name)
-                else:
-                    raise RequirementError(name=self.name)
+                    name = self.cli_name
+                    if not name:
+                        name = self.name
+                    raise RequirementError(name=name)
             return
         if self.multivalue:
             if type(value) is not tuple:
@@ -744,7 +744,10 @@ class Param(ReadOnly):

     def _validate_scalar(self, value, index=None):
         if type(value) is not self.type:
-            raise ValidationError(name=self.name,
+            name = self.cli_name
+            if not name:
+                name = self.name
+            raise ValidationError(name=name,
                 error='need a %r; got %r (a %r)' % (
                     self.type, value, type(value)
                 )
@@ -1672,10 +1675,16 @@ class AccessTime(Str):
         try:
             self._check(value)
         except ValueError, e:
-            raise ValidationError(name=self.cli_name, error=e.args[0])
+            name = self.cli_name
+            if not name:
+                name = self.name
+            raise ValidationError(name=name, error=e.args[0])
         except IndexError:
+            name = self.cli_name
+            if not name:
+                name = self.name
             raise ValidationError(
-                name=self.cli_name, error='incomplete time value'
+                name=name, error='incomplete time value'
             )
         return None


-- 
/ Alexander Bokovoy

_______________________________________________
Freeipa-devel mailing list
Freeipa-devel@redhat.com
https://www.redhat.com/mailman/listinfo/freeipa-devel

Reply via email to