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
=== modified file 'bzrlib/remote.py'
--- bzrlib/remote.py 2011-11-28 05:07:40 +0000
+++ bzrlib/remote.py 2011-11-28 10:06:25 +0000
@@ -119,8 +119,13 @@
119119
120 def get_format_description(self):120 def get_format_description(self):
121 if self._network_name:121 if self._network_name:
122 real_format = controldir.network_format_registry.get(self._network_name)122 try:
123 return 'Remote: ' + real_format.get_format_description()123 real_format = controldir.network_format_registry.get(
124 self._network_name)
125 except KeyError:
126 pass
127 else:
128 return 'Remote: ' + real_format.get_format_description()
124 return 'bzr remote bzrdir'129 return 'bzr remote bzrdir'
125130
126 def get_format_string(self):131 def get_format_string(self):
@@ -516,10 +521,18 @@
516 if len(branch_info) != 2:521 if len(branch_info) != 2:
517 raise errors.UnexpectedSmartServerResponse(response)522 raise errors.UnexpectedSmartServerResponse(response)
518 branch_ref, branch_name = branch_info523 branch_ref, branch_name = branch_info
519 format = controldir.network_format_registry.get(control_name)524 try:
525 format = controldir.network_format_registry.get(control_name)
526 except KeyError:
527 raise errors.UnknownFormatError(kind='control', format=control_name)
528
520 if repo_name:529 if repo_name:
521 format.repository_format = _mod_repository.network_format_registry.get(530 try:
522 repo_name)531 format.repository_format = _mod_repository.network_format_registry.get(
532 repo_name)
533 except KeyError:
534 raise errors.UnknownFormatError(kind='repository',
535 format=repo_name)
523 if branch_ref == 'ref':536 if branch_ref == 'ref':
524 # XXX: we need possible_transports here to avoid reopening the537 # XXX: we need possible_transports here to avoid reopening the
525 # connection to the referenced location538 # connection to the referenced location
@@ -528,8 +541,13 @@
528 format.set_branch_format(branch_format)541 format.set_branch_format(branch_format)
529 elif branch_ref == 'branch':542 elif branch_ref == 'branch':
530 if branch_name:543 if branch_name:
531 format.set_branch_format(544 try:
532 branch.network_format_registry.get(branch_name))545 branch_format = branch.network_format_registry.get(
546 branch_name)
547 except KeyError:
548 raise errors.UnknownFormatError(kind='branch',
549 format=branch_name)
550 format.set_branch_format(branch_format)
533 else:551 else:
534 raise errors.UnexpectedSmartServerResponse(response)552 raise errors.UnexpectedSmartServerResponse(response)
535 return format553 return format
@@ -965,8 +983,12 @@
965983
966 def _ensure_real(self):984 def _ensure_real(self):
967 if self._custom_format is None:985 if self._custom_format is None:
968 self._custom_format = _mod_repository.network_format_registry.get(986 try:
969 self._network_name)987 self._custom_format = _mod_repository.network_format_registry.get(
988 self._network_name)
989 except KeyError:
990 raise errors.UnknownFormatError(kind='repository',
991 format=self._network_name)
970992
971 @property993 @property
972 def _fetch_order(self):994 def _fetch_order(self):
@@ -2608,8 +2630,12 @@
26082630
2609 def _ensure_real(self):2631 def _ensure_real(self):
2610 if self._custom_format is None:2632 if self._custom_format is None:
2611 self._custom_format = branch.network_format_registry.get(2633 try:
2612 self._network_name)2634 self._custom_format = branch.network_format_registry.get(
2635 self._network_name)
2636 except KeyError:
2637 raise errors.UnknownFormatError(kind='branch',
2638 format=self._network_name)
26132639
2614 def get_format_description(self):2640 def get_format_description(self):
2615 self._ensure_real()2641 self._ensure_real()
26162642
=== modified file 'bzrlib/tests/test_remote.py'
--- bzrlib/tests/test_remote.py 2011-11-28 05:07:40 +0000
+++ bzrlib/tests/test_remote.py 2011-11-28 10:06:25 +0000
@@ -484,6 +484,18 @@
484 self.assertEqual(None, result._branch_format)484 self.assertEqual(None, result._branch_format)
485 self.assertFinished(client)485 self.assertFinished(client)
486486
487 def test_unknown(self):
488 transport = self.get_transport('quack')
489 referenced = self.make_branch('referenced')
490 expected = referenced.bzrdir.cloning_metadir()
491 client = FakeClient(transport.base)
492 client.add_expected_call(
493 'BzrDir.cloning_metadir', ('quack/', 'False'),
494 'success', ('unknown', 'unknown', ('branch', ''))),
495 a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
496 _client=client)
497 self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
498
487499
488class TestBzrDirDestroyBranch(TestRemote):500class TestBzrDirDestroyBranch(TestRemote):
489501
490502
=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- doc/en/release-notes/bzr-2.5.txt 2011-11-28 03:38:43 +0000
+++ doc/en/release-notes/bzr-2.5.txt 2011-11-28 10:06:25 +0000
@@ -78,6 +78,9 @@
78 and gives a better error message if the time zone offset is not given.78 and gives a better error message if the time zone offset is not given.
79 (Matt Giuca, #892657)79 (Matt Giuca, #892657)
8080
81* When a remote format is unknown, bzr will now print a single-line error
82 message rather than a backtrace. (Jelmer Vernooij, #687226)
83
81Documentation84Documentation
82*************85*************
8386