[MERGE] Make cmd_branch check the destination before doing any I/O on the source.

Michael Ellerman michael at ellerman.id.au
Wed Jul 26 05:07:19 BST 2006


On Wed, 2006-07-26 at 10:48 +1000, Andrew Bennetts wrote:
> On Tue, Jul 25, 2006 at 01:48:31PM -0500, John Arbash Meinel wrote:
> [...]
> > The only thing it really means is that if we get an exception, and then
> > delete_tree() also raises, it will hide the original exception.
> > The only way I know around it is:
> > 
> > except Exception, e:
> >   try:
> >     to_transport.delete_tree('.')
> >   except:
> >     raise e
> >   raise
> > 
> > That will raise the original exception delete_tree() fails, though you
> > lose the traceback. And if delete_tree() succeeds, it raises the
> > original exception with the original traceback.
> 
> You can do slightly better with sys.exc_info():
> 
> except Exception, e:
>   exc_value, exc_type, exc_tb = sys.exc_info()
>   try:
>     to_transport.delete_tree('.')
>   except:
>     raise exc_value, exc_type, exc_tb
>   raise
> 
> This preserves the original exception, although the code is a bit uglier.

Could we wrap it in a function?

eg.

def execute_then_raise(callable, *args, **kwargs):
	exc_value, exc_type, exc_tb = sys.exc_info()
	try:
		callable(*args, **kwargs)
	except:
		pass
	raise exc_value, exc_type, exc_tb


cheers

-- 
Michael Ellerman
IBM OzLabs

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060726/496cf260/attachment.pgp 


More information about the bazaar mailing list