[Freeipa-devel] Exception model proposal

Kevin McCarthy kmccarth at redhat.com
Mon Aug 27 15:33:47 UTC 2007


Karl MacMillan wrote:
> On Tue, 2007-08-21 at 17:17 -0700, Kevin McCarthy wrote:
> > I've been playing with the exception model, and here's my code so far.
> > This uses Simo's suggestion of segmenting errors into 16 bit categories
> > and 16 bit "detail" error codes.
> > 
> > This is not ready for committing - just wanted to get some feedback
> > before I finish working on it tomorrow.
> > 
> > 
> > All exceptions inherit from IPAError.
> > 
> > Sample code to throw an exception:
> >     raise ipaerror.gen_exception(ipaerror.LDAP_DUPLICATE)
> > 
> 
> Forcing the use of these functions seems cumbersome to me - I guess this
> is caused by having a single exception type. I'd prefer to have
> exception classes for each exception as it would allow you to use the
> base language features for raising and filtering exceptions. You could
> still have the error codes set as you have here.

There are actually independent exceptions corresponding to each error
code.  I'm dynamically generating them inside ipaerror.gen_error_code():

    exception = types.ClassType("IPAError%d" % code,
                      (IPAError,),
                      {})

The primary reason I went with the gen_exception approach is because of
xmlrpc.  It makes it easy to regenerate the exception on the client side
from the error code transmitted over xmlrpc:
        try:
            result = server.update_user(ipautil.wrap_binary_data(olduser),
                    ipautil.wrap_binary_data(newuser))
        except xmlrpclib.Fault, fault:
            raise ipaerror.gen_exception(fault.faultCode, fault.faultString)

If this is a big issue, we could give each exception a more readable
name when it's generated inside gen_error_code by passing in a string
too and appending that to IPAError instead of the numeric code.

-Kevin

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 2228 bytes
Desc: not available
URL: <http://listman.redhat.com/archives/freeipa-devel/attachments/20070827/910741bf/attachment.bin>


More information about the Freeipa-devel mailing list