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

John Arbash Meinel john at arbash-meinel.com
Thu Jul 17 23:26:23 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew Bennetts wrote:
| 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.
|
|

This would seem like a great place to directly test the translation
functionality.

BB:tweak

I'm a bit concerned that a typo somewhere, or a missing context is going
to cause a KeyError rather than raising the correct exception, just
without the expected context.

I suppose that might make it more obvious that it is happening, and get
us to fix it, though. If I was debugging, I'd want the KeyError. If I
was a *user* I'd want the regular exception.

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkh/xw8ACgkQJdeBCYSNAAOfOgCdERU5lGmcMQq0MOdRkytgcJVT
uhMAoJi2sr+OJOkVn+Docf+wxcgPw6Av
=WvdF
-----END PGP SIGNATURE-----



More information about the bazaar mailing list