[MERGE] Make cmd_branch check the destination before doing any I/O on the source.
John Arbash Meinel
john at arbash-meinel.com
Wed Jul 26 22:03:58 BST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Michael Ellerman wrote:
> 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
>
It would seem that you should be able to. Though I wonder if it isn't
better to do:
def cleanup_then_raise(cleanup, *args, **kwargs):
exc_value, exc_type, exc_tb = sys.exc_info()
try:
cleanup(*args, **kwargs)
except:
raise exc_value, exc_type, exc_tb
raise
I would be okay with 'callable', but I think this makes it clearer when
we actually want to use the function.
John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFEx9i+JdeBCYSNAAMRAuEmAJ4uovqbNnYEPCLt//qvhQXaSYID6gCfebPO
u/Ze5WdfdH5WiKytABWb3nY=
=RuwA
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list