Rev 6312: (jelmer) Print a sensible error message rather than a KeyError with a in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Mon Nov 28 11:49:44 UTC 2011


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6312 [merge]
revision-id: pqm at pqm.ubuntu.com-20111128114943-exp17aodb5tydnkj
parent: pqm at pqm.ubuntu.com-20111128103340-4fwv8lav4ksmehbs
parent: jelmer at samba.org-20111128095722-30xzuqc3f0u335vq
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2011-11-28 11:49:43 +0000
message:
  (jelmer) Print a sensible error message rather than a KeyError with a
   backtrace when a format is unknown. (Jelmer Vernooij)
modified:
  bzrlib/remote.py               remote.py-20060720103555-yeeg2x51vn0rbtdp-1
  bzrlib/tests/test_remote.py    test_remote.py-20060720103555-yeeg2x51vn0rbtdp-2
  doc/en/release-notes/bzr-2.5.txt bzr2.5.txt-20110708125756-587p0hpw7oke4h05-1
=== modified file 'bzrlib/remote.py'
--- a/bzrlib/remote.py	2011-11-28 10:33:40 +0000
+++ b/bzrlib/remote.py	2011-11-28 11:49:43 +0000
@@ -119,8 +119,13 @@
 
     def get_format_description(self):
         if self._network_name:
-            real_format = controldir.network_format_registry.get(self._network_name)
-            return 'Remote: ' + real_format.get_format_description()
+            try:
+                real_format = controldir.network_format_registry.get(
+                        self._network_name)
+            except KeyError:
+                pass
+            else:
+                return 'Remote: ' + real_format.get_format_description()
         return 'bzr remote bzrdir'
 
     def get_format_string(self):
@@ -516,10 +521,18 @@
         if len(branch_info) != 2:
             raise errors.UnexpectedSmartServerResponse(response)
         branch_ref, branch_name = branch_info
-        format = controldir.network_format_registry.get(control_name)
+        try:
+            format = controldir.network_format_registry.get(control_name)
+        except KeyError:
+            raise errors.UnknownFormatError(kind='control', format=control_name)
+
         if repo_name:
-            format.repository_format = _mod_repository.network_format_registry.get(
-                repo_name)
+            try:
+                format.repository_format = _mod_repository.network_format_registry.get(
+                    repo_name)
+            except KeyError:
+                raise errors.UnknownFormatError(kind='repository',
+                    format=repo_name)
         if branch_ref == 'ref':
             # XXX: we need possible_transports here to avoid reopening the
             # connection to the referenced location
@@ -528,8 +541,13 @@
             format.set_branch_format(branch_format)
         elif branch_ref == 'branch':
             if branch_name:
-                format.set_branch_format(
-                    branch.network_format_registry.get(branch_name))
+                try:
+                    branch_format = branch.network_format_registry.get(
+                        branch_name)
+                except KeyError:
+                    raise errors.UnknownFormatError(kind='branch',
+                        format=branch_name)
+                format.set_branch_format(branch_format)
         else:
             raise errors.UnexpectedSmartServerResponse(response)
         return format
@@ -967,8 +985,12 @@
 
     def _ensure_real(self):
         if self._custom_format is None:
-            self._custom_format = _mod_repository.network_format_registry.get(
-                self._network_name)
+            try:
+                self._custom_format = _mod_repository.network_format_registry.get(
+                    self._network_name)
+            except KeyError:
+                raise errors.UnknownFormatError(kind='repository',
+                    format=self._network_name)
 
     @property
     def _fetch_order(self):
@@ -2610,8 +2632,12 @@
 
     def _ensure_real(self):
         if self._custom_format is None:
-            self._custom_format = branch.network_format_registry.get(
-                self._network_name)
+            try:
+                self._custom_format = branch.network_format_registry.get(
+                    self._network_name)
+            except KeyError:
+                raise errors.UnknownFormatError(kind='branch',
+                    format=self._network_name)
 
     def get_format_description(self):
         self._ensure_real()

=== modified file 'bzrlib/tests/test_remote.py'
--- a/bzrlib/tests/test_remote.py	2011-11-28 10:33:40 +0000
+++ b/bzrlib/tests/test_remote.py	2011-11-28 11:49:43 +0000
@@ -484,6 +484,18 @@
         self.assertEqual(None, result._branch_format)
         self.assertFinished(client)
 
+    def test_unknown(self):
+        transport = self.get_transport('quack')
+        referenced = self.make_branch('referenced')
+        expected = referenced.bzrdir.cloning_metadir()
+        client = FakeClient(transport.base)
+        client.add_expected_call(
+            'BzrDir.cloning_metadir', ('quack/', 'False'),
+            'success', ('unknown', 'unknown', ('branch', ''))),
+        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
+            _client=client)
+        self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
+
 
 class TestBzrDirDestroyBranch(TestRemote):
 

=== modified file 'doc/en/release-notes/bzr-2.5.txt'
--- a/doc/en/release-notes/bzr-2.5.txt	2011-11-28 10:33:40 +0000
+++ b/doc/en/release-notes/bzr-2.5.txt	2011-11-28 11:49:43 +0000
@@ -81,6 +81,9 @@
   and gives a better error message if the time zone offset is not given.
   (Matt Giuca, #892657)
 
+* When a remote format is unknown, bzr will now print a single-line error
+  message rather than a backtrace. (Jelmer Vernooij, #687226)
+
 Documentation
 *************
 




More information about the bazaar-commits mailing list