On Mon, 2012-03-19 at 15:41 -0400, Rob Crittenden wrote: > Martin Kosek wrote: > > On Mon, 2012-03-19 at 14:43 -0400, Rob Crittenden wrote: > >> Petr Viktorin wrote: > >>> On 03/19/2012 03:02 PM, Rob Crittenden wrote: > >>>> Petr Viktorin wrote: > >>>>> On 03/16/2012 10:23 PM, Rob Crittenden wrote: > >>>>>> When using *attr we should return the param.name of in the exception > >>>>>> and > >>>>>> when using a cli option we should return param.cli_name. This didn't > >>>>>> work consistently in the framework. > >>>>>> > >>>>>> This is a bit of a kludge, catching exceptions and re-raising them, but > >>>>>> it is a less invasive way of doing it. > >>>>>> > >>>>>> I added some examples of things to test in the ticket. > >>>>>> > >>>>>> rob > >>>>>> > >>>>> > >>>>>> (name, error) = err.strerror.split(':') > >>>>>> raise errors.ConversionError(name=attr, error=error) > >>>>> > >>>>> AFAIU this will break when the error message is translated. Why not just > >>>>> use err.kw['error']? > >>>>> > >>>> > >>>> Because the attribute name needs to get pulled out of it. > >>>> > >>>> rob > >>> > >>> No, you're ignoring the attribute name. > >>> Anyway, even the English error messages are 'invalid %(name)r: > >>> %(error)s', so "name" part starts with 'invalid ', and the "error" part > >>> starts with an extra space. > >> > >> The error gets re-raised so there is no dup "invalid". I'll grant you > >> the extra space though. > >> > >> What this does is catch something like 'invalid maxfail: something bad', > >> split out the attribute/error and re-raise use the attribute name we want. > > > > I think this is what Petr wanted to point out - you can access the > > attributes passed to our PublicErrors directly, i.e. you don't have to > > parse it from its string representation: > > > >>>> from ipalib import errors > >>>> x = errors.ValidationError(name='foo', error=u'Invalid value!') > >>>> print str(x) > > invalid 'foo': Invalid value! > >>>> x.name > > 'foo' > >>>> x.error > > u'Invalid value!' > > > > Martin > > > > Of course, can't believe I missed that. > > Rebased against ipa-2-2. > > rob
Yeah, this one is much better. ACK, pushed to master, ipa-2-2. Martin _______________________________________________ Freeipa-devel mailing list Freeipa-devel@redhat.com https://www.redhat.com/mailman/listinfo/freeipa-devel