Merge lp:~jelmer/bzr/hpss-unknown-format into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 6312
Proposed branch: lp:~jelmer/bzr/hpss-unknown-format
Merge into: lp:bzr
Diff against target: 123 lines (+52/-11)
3 files modified
bzrlib/remote.py (+37/-11)
bzrlib/tests/test_remote.py (+12/-0)
doc/en/release-notes/bzr-2.5.txt (+3/-0)
To merge this branch: bzr merge lp:~jelmer/bzr/hpss-unknown-format
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+83523@code.launchpad.net

Commit message

Print a sensible error message rather than a KeyError with a backtrace when a format is unknown.

Description of the change

Print a sensible "unknown format error" rather than a keyerror with a backtrace,
when a remote format is unknown.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

it seems a little duplicative, but ok

  vote approve
  review approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/remote.py'
2--- bzrlib/remote.py 2011-11-28 05:07:40 +0000
3+++ bzrlib/remote.py 2011-11-28 10:06:25 +0000
4@@ -119,8 +119,13 @@
5
6 def get_format_description(self):
7 if self._network_name:
8- real_format = controldir.network_format_registry.get(self._network_name)
9- return 'Remote: ' + real_format.get_format_description()
10+ try:
11+ real_format = controldir.network_format_registry.get(
12+ self._network_name)
13+ except KeyError:
14+ pass
15+ else:
16+ return 'Remote: ' + real_format.get_format_description()
17 return 'bzr remote bzrdir'
18
19 def get_format_string(self):
20@@ -516,10 +521,18 @@
21 if len(branch_info) != 2:
22 raise errors.UnexpectedSmartServerResponse(response)
23 branch_ref, branch_name = branch_info
24- format = controldir.network_format_registry.get(control_name)
25+ try:
26+ format = controldir.network_format_registry.get(control_name)
27+ except KeyError:
28+ raise errors.UnknownFormatError(kind='control', format=control_name)
29+
30 if repo_name:
31- format.repository_format = _mod_repository.network_format_registry.get(
32- repo_name)
33+ try:
34+ format.repository_format = _mod_repository.network_format_registry.get(
35+ repo_name)
36+ except KeyError:
37+ raise errors.UnknownFormatError(kind='repository',
38+ format=repo_name)
39 if branch_ref == 'ref':
40 # XXX: we need possible_transports here to avoid reopening the
41 # connection to the referenced location
42@@ -528,8 +541,13 @@
43 format.set_branch_format(branch_format)
44 elif branch_ref == 'branch':
45 if branch_name:
46- format.set_branch_format(
47- branch.network_format_registry.get(branch_name))
48+ try:
49+ branch_format = branch.network_format_registry.get(
50+ branch_name)
51+ except KeyError:
52+ raise errors.UnknownFormatError(kind='branch',
53+ format=branch_name)
54+ format.set_branch_format(branch_format)
55 else:
56 raise errors.UnexpectedSmartServerResponse(response)
57 return format
58@@ -965,8 +983,12 @@
59
60 def _ensure_real(self):
61 if self._custom_format is None:
62- self._custom_format = _mod_repository.network_format_registry.get(
63- self._network_name)
64+ try:
65+ self._custom_format = _mod_repository.network_format_registry.get(
66+ self._network_name)
67+ except KeyError:
68+ raise errors.UnknownFormatError(kind='repository',
69+ format=self._network_name)
70
71 @property
72 def _fetch_order(self):
73@@ -2608,8 +2630,12 @@
74
75 def _ensure_real(self):
76 if self._custom_format is None:
77- self._custom_format = branch.network_format_registry.get(
78- self._network_name)
79+ try:
80+ self._custom_format = branch.network_format_registry.get(
81+ self._network_name)
82+ except KeyError:
83+ raise errors.UnknownFormatError(kind='branch',
84+ format=self._network_name)
85
86 def get_format_description(self):
87 self._ensure_real()
88
89=== modified file 'bzrlib/tests/test_remote.py'
90--- bzrlib/tests/test_remote.py 2011-11-28 05:07:40 +0000
91+++ bzrlib/tests/test_remote.py 2011-11-28 10:06:25 +0000
92@@ -484,6 +484,18 @@
93 self.assertEqual(None, result._branch_format)
94 self.assertFinished(client)
95
96+ def test_unknown(self):
97+ transport = self.get_transport('quack')
98+ referenced = self.make_branch('referenced')
99+ expected = referenced.bzrdir.cloning_metadir()
100+ client = FakeClient(transport.base)
101+ client.add_expected_call(
102+ 'BzrDir.cloning_metadir', ('quack/', 'False'),
103+ 'success', ('unknown', 'unknown', ('branch', ''))),
104+ a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
105+ _client=client)
106+ self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
107+
108
109 class TestBzrDirDestroyBranch(TestRemote):
110
111
112=== modified file 'doc/en/release-notes/bzr-2.5.txt'
113--- doc/en/release-notes/bzr-2.5.txt 2011-11-28 03:38:43 +0000
114+++ doc/en/release-notes/bzr-2.5.txt 2011-11-28 10:06:25 +0000
115@@ -78,6 +78,9 @@
116 and gives a better error message if the time zone offset is not given.
117 (Matt Giuca, #892657)
118
119+* When a remote format is unknown, bzr will now print a single-line error
120+ message rather than a backtrace. (Jelmer Vernooij, #687226)
121+
122 Documentation
123 *************
124