[MERGE] Remove duplication of error translation in bzrlib/remote.py.

Andrew Bennetts andrew at canonical.com
Wed Jul 9 05:42:48 BST 2008


Hi,

In the course of doing other work on remote.py the duplication of error handling
logic finally bugged me enough to do something about it.  The problem had been
that a simple "translate_error(err)" function wouldn't have enough context to
construct appropriate exceptions.  Exceptions like NoSuchRevision or
TokenMismatch need branch objects or other objects not part of the error
response sent over the wire.

So, I've defined a _translate_error(err, **context) function, and added
_translate_error helper methods to RemoteBzrDir/Branch/Repository to fill in the
context.  Most places in remote.py can just do:

    try:
        self._client.call(...)
    except errors.ErrorFromSmartServer, err:
        self._translate_error(err)

A handful of places pass extra args like token=token to self._translate_error if
necessary.

This doesn't help with translating successful responses into errors (e.g.
BzrDir.find_repository returns a successful response of ('no', ...), rather than
an error), but I think it's still worthwhile.

-Andrew.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: remote-error-translation-3534.patch
Type: text/x-diff
Size: 14075 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20080709/2713b168/attachment-0001.bin 


More information about the bazaar mailing list