Rev 2855: Fix "unprintable error" message for BzrCheckError and others in http://sourcefrog.net/bzr/exception-keyerrors
Martin Pool
mbp at sourcefrog.net
Tue Sep 25 07:29:48 BST 2007
At http://sourcefrog.net/bzr/exception-keyerrors
------------------------------------------------------------
revno: 2855
revision-id: mbp at sourcefrog.net-20070925062946-1tlmmt604lf9bllm
parent: pqm at pqm.ubuntu.com-20070924212812-g325vvenhnfktgbh
committer: Martin Pool <mbp at sourcefrog.net>
branch nick: exception-keyerrors
timestamp: Tue 2007-09-25 16:29:46 +1000
message:
Fix "unprintable error" message for BzrCheckError and others
modified:
NEWS NEWS-20050323055033-4e00b5db738777ff
bzrlib/errors.py errors.py-20050309040759-20512168c4e14fbd
bzrlib/tests/test_errors.py test_errors.py-20060210110251-41aba2deddf936a8
=== modified file 'NEWS'
--- a/NEWS 2007-09-24 09:40:01 +0000
+++ b/NEWS 2007-09-25 06:29:46 +0000
@@ -79,6 +79,10 @@
contains a symbolic link.
(Vincent Ladeuil, #141382).
+ * Fix 'unprintable error' message when displaying BzrCheckError and
+ some other exceptions on Python 2.5.
+ (Martin Pool, #144633)
+
* HttpServer and FtpServer need to be closed properly or a listening socket
will remain opened.
(Vincent Ladeuil, #140055)
=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py 2007-09-13 01:54:49 +0000
+++ b/bzrlib/errors.py 2007-09-25 06:29:46 +0000
@@ -95,7 +95,11 @@
try:
fmt = self._get_format_string()
if fmt:
- s = fmt % self.__dict__
+ d = (self.__dict__)
+ # special case: python2.5 puts the 'message' attribute in a
+ # slot, so it isn't seen in __dict__
+ d['message'] = getattr(self, 'message', 'dummy message')
+ s = fmt % d
# __str__() should always return a 'str' object
# never a 'unicode' object.
if isinstance(s, unicode):
@@ -783,8 +787,8 @@
# New code should prefer to raise specific subclasses
def __init__(self, message):
# Python 2.5 uses a slot for StandardError.message,
- # so use a different variable name
- # so it is exposed in self.__dict__
+ # so use a different variable name. We now work around this in
+ # BzrError.__str__, but this member name is kept for compatability.
self.msg = message
=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py 2007-08-30 08:11:54 +0000
+++ b/bzrlib/tests/test_errors.py 2007-09-25 06:29:46 +0000
@@ -361,6 +361,15 @@
self.assertEqual(
"Container has multiple records with the same name: n\xc3\xa5me",
str(e))
+
+ def test_check_error(self):
+ # This has a member called 'message', which is problematic in
+ # python2.5 because that is a slot on the base Exception class
+ e = errors.BzrCheckError('example check failure')
+ self.assertEqual(
+ "Internal check failed: example check failure",
+ str(e))
+ self.assertTrue(e.internal_error)
class PassThroughError(errors.BzrError):
More information about the bazaar-commits
mailing list