Rev 5102: (spiv) Don't propagate unexpected exceptions during NotBranchError.__str__ in file:///home/pqm/archives/thelove/bzr/2.2/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Oct 11 08:09:19 BST 2010


At file:///home/pqm/archives/thelove/bzr/2.2/

------------------------------------------------------------
revno: 5102 [merge]
revision-id: pqm at pqm.ubuntu.com-20101011070915-gohqlskch0709gq5
parent: pqm at pqm.ubuntu.com-20101008121738-exwxfxq5u3q0444z
parent: andrew.bennetts at canonical.com-20101011050626-kql01ndwvploy97a
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: 2.2
timestamp: Mon 2010-10-11 08:09:15 +0100
message:
  (spiv) Don't propagate unexpected exceptions during NotBranchError.__str__
   (Andrew Bennetts)
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	2010-10-08 10:09:37 +0000
+++ b/NEWS	2010-10-11 07:09:15 +0000
@@ -19,6 +19,10 @@
 Bug Fixes
 *********
 
+* ``NotBranchError`` no longer allows errors from calling
+  ``bzrdir.open_repository()`` to propagate.  This is unhelpful at best,
+  and at worst can trigger infinite loops in callers.  (Andrew Bennetts)
+  
 * Skip tests that needs a bzr source tree when there isn't one. This is
   needed to succesfully run the test suite for installed versions.
   (Vincent Ladeuil, #644855).

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2010-09-13 02:32:44 +0000
+++ b/bzrlib/errors.py	2010-10-11 05:06:26 +0000
@@ -723,6 +723,15 @@
                     self.bzrdir.open_repository()
                 except NoRepositoryPresent:
                     self.detail = ''
+                except Exception:
+                    # Just ignore unexpected errors.  Raising arbitrary errors
+                    # during str(err) can provoke strange bugs.  Concretely
+                    # Launchpad's codehosting managed to raise NotBranchError
+                    # here, and then get stuck in an infinite loop/recursion
+                    # trying to str() that error.  All this error really cares
+                    # about that there's no working repository there, and if
+                    # open_repository() fails, there probably isn't.
+                    self.detail = ''
                 else:
                     self.detail = ': location is a repository'
             else:

=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py	2010-09-13 02:32:44 +0000
+++ b/bzrlib/tests/test_errors.py	2010-10-11 05:06:26 +0000
@@ -672,6 +672,15 @@
         err = errors.NotBranchError('path', bzrdir=bzrdir)
         self.assertEqual('Not a branch: "path".', str(err))
 
+    def test_not_branch_bzrdir_with_recursive_not_branch_error(self):
+        class FakeBzrDir(object):
+            def open_repository(self):
+                # str() on the NotBranchError will trigger a call to this,
+                # which in turn will another, identical NotBranchError.
+                raise errors.NotBranchError('path', bzrdir=FakeBzrDir())
+        err = errors.NotBranchError('path', bzrdir=FakeBzrDir())
+        self.assertEqual('Not a branch: "path".', str(err))
+
     def test_not_branch_laziness(self):
         real_bzrdir = self.make_bzrdir('path')
         class FakeBzrDir(object):




More information about the bazaar-commits mailing list