Rev 5246: (spiv) Treat pywintypes.error as a user error as per OSError, in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri May 21 07:14:54 BST 2010


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

------------------------------------------------------------
revno: 5246 [merge]
revision-id: pqm at pqm.ubuntu.com-20100521061450-57wjgoabefym6l9b
parent: pqm at pqm.ubuntu.com-20100521045717-qe9khoe3xia0fqwm
parent: gzlist at googlemail.com-20100520214502-ytsaoouqzq901jfd
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2010-05-21 07:14:50 +0100
message:
  (spiv) Treat pywintypes.error as a user error as per OSError,
   rather than an internal error (Martin [gz])
modified:
  bzrlib/tests/features.py       features.py-20090820042958-jglgza3wrn03ha9e-1
  bzrlib/tests/test_trace.py     testtrace.py-20051110225523-a21117fc7a07eeff
  bzrlib/trace.py                trace.py-20050309040759-c8ed824bdcd4748a
=== modified file 'bzrlib/tests/features.py'
--- a/bzrlib/tests/features.py	2010-05-20 02:57:52 +0000
+++ b/bzrlib/tests/features.py	2010-05-21 06:14:50 +0000
@@ -26,6 +26,7 @@
 apport = tests.ModuleAvailableFeature('apport')
 paramiko = tests.ModuleAvailableFeature('paramiko')
 pycurl = tests.ModuleAvailableFeature('pycurl')
+pywintypes = tests.ModuleAvailableFeature('pywintypes')
 subunit = tests.ModuleAvailableFeature('subunit')
 
 

=== modified file 'bzrlib/tests/test_trace.py'
--- a/bzrlib/tests/test_trace.py	2010-02-25 13:15:08 +0000
+++ b/bzrlib/tests/test_trace.py	2010-05-20 21:45:02 +0000
@@ -29,7 +29,7 @@
     errors,
     trace,
     )
-from bzrlib.tests import TestCaseInTempDir, TestCase
+from bzrlib.tests import features, TestCaseInTempDir, TestCase
 from bzrlib.trace import (
     mutter, mutter_callsite, report_exception,
     set_verbosity_level, get_verbosity_level, is_quiet, is_verbose, be_quiet,
@@ -104,6 +104,19 @@
         self.assertContainsRe(msg,
             r'^bzr: ERROR: \[Errno .*\] No such file.*nosuchfile')
 
+    def test_format_pywintypes_error(self):
+        self.requireFeature(features.pywintypes)
+        import pywintypes, win32file
+        try:
+            win32file.RemoveDirectory('nosuchfile22222')
+        except pywintypes.error:
+            pass
+        msg = _format_exception()
+        # GZ 2010-05-03: Formatting for pywintypes.error is basic, a 3-tuple
+        #                with errno, function name, and locale error message
+        self.assertContainsRe(msg,
+            r"^bzr: ERROR: \(2, 'RemoveDirectory[AW]?', .*\)")
+
     def test_format_unicode_error(self):
         try:
             raise errors.BzrCommandError(u'argument foo\xb5 does not exist')

=== modified file 'bzrlib/trace.py'
--- a/bzrlib/trace.py	2010-05-05 02:35:02 +0000
+++ b/bzrlib/trace.py	2010-05-21 06:14:50 +0000
@@ -498,7 +498,9 @@
     elif not getattr(exc_object, 'internal_error', True):
         report_user_error(exc_info, err_file)
         return errors.EXIT_ERROR
-    elif isinstance(exc_object, (OSError, IOError)):
+    elif isinstance(exc_object, (OSError, IOError)) or (
+        # GZ 2010-05-20: Like (exc_type is pywintypes.error) but avoid import
+        exc_type.__name__ == "error" and exc_type.__module__ == "pywintypes"):
         # Might be nice to catch all of these and show them as something more
         # specific, but there are too many cases at the moment.
         report_user_error(exc_info, err_file)




More information about the bazaar-commits mailing list