Merge lp:~spiv/bzr/notbrancherror-recursion-2.2 into lp:bzr/2.2

Proposed by Andrew Bennetts on 2010-10-11
Status: Merged
Approved by: Martin Pool on 2010-10-11
Approved revision: 5101
Merged at revision: 5102
Proposed branch: lp:~spiv/bzr/notbrancherror-recursion-2.2
Merge into: lp:bzr/2.2
Diff against target: 54 lines (+22/-0)
3 files modified
NEWS (+4/-0)
bzrlib/errors.py (+9/-0)
bzrlib/tests/test_errors.py (+9/-0)
To merge this branch: bzr merge lp:~spiv/bzr/notbrancherror-recursion-2.2
Reviewer Review Type Date Requested Status
Martin Pool 2010-10-11 Approve on 2010-10-11
Review via email: mp+38094@code.launchpad.net

Commit Message

Don't propagate unexpected exceptions during NotBranchError.__str__

Description of the Change

This adds a bit of safety to NotBranchError. Tim Penhey encountered a situation where the Launchpad codehosting server would fall into an infinite loop because str() of a NotBranchError would trigger another NotBranchError.

Strictly speaking an infinite loop in that situation is a bug in the caller, but I don't see any harm in suppressing unexpected errors at that point. The open_repository call is only there to provide a hint in the str-ified error, and an error is enough to decide the hint isn't needed. And not obliterating the original error is likely to be more useful.

If we wanted to be extra conservative, we could just trap NotBranchError rather than Exception at that point, to only deal with the specific reported issue. But I think we may as well fix the slightly more general issue.

To post a comment you must log in.
Martin Pool (mbp) :
review: Approve
Andrew Bennetts (spiv) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-10-08 10:09:37 +0000
3+++ NEWS 2010-10-11 05:14:40 +0000
4@@ -19,6 +19,10 @@
5 Bug Fixes
6 *********
7
8+* ``NotBranchError`` no longer allows errors from calling
9+ ``bzrdir.open_repository()`` to propagate. This is unhelpful at best,
10+ and at worst can trigger infinite loops in callers. (Andrew Bennetts)
11+
12 * Skip tests that needs a bzr source tree when there isn't one. This is
13 needed to succesfully run the test suite for installed versions.
14 (Vincent Ladeuil, #644855).
15
16=== modified file 'bzrlib/errors.py'
17--- bzrlib/errors.py 2010-09-13 02:32:44 +0000
18+++ bzrlib/errors.py 2010-10-11 05:14:40 +0000
19@@ -723,6 +723,15 @@
20 self.bzrdir.open_repository()
21 except NoRepositoryPresent:
22 self.detail = ''
23+ except Exception:
24+ # Just ignore unexpected errors. Raising arbitrary errors
25+ # during str(err) can provoke strange bugs. Concretely
26+ # Launchpad's codehosting managed to raise NotBranchError
27+ # here, and then get stuck in an infinite loop/recursion
28+ # trying to str() that error. All this error really cares
29+ # about that there's no working repository there, and if
30+ # open_repository() fails, there probably isn't.
31+ self.detail = ''
32 else:
33 self.detail = ': location is a repository'
34 else:
35
36=== modified file 'bzrlib/tests/test_errors.py'
37--- bzrlib/tests/test_errors.py 2010-09-13 02:32:44 +0000
38+++ bzrlib/tests/test_errors.py 2010-10-11 05:14:40 +0000
39@@ -672,6 +672,15 @@
40 err = errors.NotBranchError('path', bzrdir=bzrdir)
41 self.assertEqual('Not a branch: "path".', str(err))
42
43+ def test_not_branch_bzrdir_with_recursive_not_branch_error(self):
44+ class FakeBzrDir(object):
45+ def open_repository(self):
46+ # str() on the NotBranchError will trigger a call to this,
47+ # which in turn will another, identical NotBranchError.
48+ raise errors.NotBranchError('path', bzrdir=FakeBzrDir())
49+ err = errors.NotBranchError('path', bzrdir=FakeBzrDir())
50+ self.assertEqual('Not a branch: "path".', str(err))
51+
52 def test_not_branch_laziness(self):
53 real_bzrdir = self.make_bzrdir('path')
54 class FakeBzrDir(object):

Subscribers

People subscribed via source and target branches