Rev 2457: (robertc) Use repr rather than str when reporting an unprintable exception to aid debugging. (Robert Collins) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Thu Apr 26 03:19:45 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2457
revision-id: pqm at pqm.ubuntu.com-20070426021942-eutaiob3qgh6kln8
parent: pqm at pqm.ubuntu.com-20070425143732-c4aa489eylhhfnzg
parent: robertc at robertcollins.net-20070426014829-znbzqzsk1gq68xqh
committer: Canonical.com Patch Queue Manager<pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Thu 2007-04-26 03:19:42 +0100
message:
  (robertc) Use repr rather than str when reporting an unprintable exception to aid debugging. (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
    ------------------------------------------------------------
    revno: 2456.1.1
    merged: robertc at robertcollins.net-20070426014829-znbzqzsk1gq68xqh
    parent: pqm at pqm.ubuntu.com-20070425143732-c4aa489eylhhfnzg
    committer: Robert Collins <robertc at robertcollins.net>
    branch nick: integration
    timestamp: Thu 2007-04-26 11:48:29 +1000
    message:
      Fix the 'Unprintable error' message display to use the repr of the
      exception that prevented printing the error because the str value for it
      is often not useful in debugging (e.g.  KeyError('foo') has a str() of
      'foo' but a repr of 'KeyError('foo')' which is much more useful.
      (Robert Collins)
=== modified file 'NEWS'
--- a/NEWS	2007-04-25 14:37:32 +0000
+++ b/NEWS	2007-04-26 01:48:29 +0000
@@ -159,6 +159,12 @@
       sense to generate them from a ``Branch`` object.
       (John Arbash Meinel)
 
+    * Fix the 'Unprintable error' message display to use the repr of the 
+      exception that prevented printing the error because the str value
+      for it is often not useful in debugging (e.g. KeyError('foo') has a
+      str() of 'foo' but a repr of 'KeyError('foo')' which is much more
+      useful. (Robert Collins)
+
   BUGFIXES:
 
     * Don't fail bundle selftest if email has 'two' embedded.  

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2007-04-25 06:50:22 +0000
+++ b/bzrlib/errors.py	2007-04-26 01:48:29 +0000
@@ -102,11 +102,11 @@
                     return s.encode('utf8')
                 return s
         except (AttributeError, TypeError, NameError, ValueError, KeyError), e:
-            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%s' \
+            return 'Unprintable exception %s: dict=%r, fmt=%r, error=%r' \
                 % (self.__class__.__name__,
                    self.__dict__,
                    getattr(self, '_fmt', None),
-                   str(e))
+                   e)
 
     def _get_format_string(self):
         """Return format string for this exception or None"""
@@ -154,9 +154,9 @@
                 return s.encode('utf8')
             return s
         except (TypeError, NameError, ValueError, KeyError), e:
-            return 'Unprintable exception %s(%r): %s' \
+            return 'Unprintable exception %s(%r): %r' \
                 % (self.__class__.__name__,
-                   self.__dict__, str(e))
+                   self.__dict__, e)
 
 
 class AlreadyBuilding(BzrError):




More information about the bazaar-commits mailing list