changeset 21617:0cfda08afd24

bundle2: rename UnknownPartError to BundleValueError We are going to raise exceptions for a wider range of cases: unsupported mandatory stream and part parameters. We rename the exception with a wider name.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 28 May 2014 14:22:24 -0700
parents 0a8e7f81e8ae
children 7568f5c1c801
files mercurial/bundle2.py mercurial/exchange.py mercurial/wireproto.py tests/test-bundle2.t
diffstat 4 files changed, 15 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Tue May 27 17:04:48 2014 -0500
+++ b/mercurial/bundle2.py	Wed May 28 14:22:24 2014 -0700
@@ -172,8 +172,10 @@
     """
     return '>'+('BB'*nbparams)
 
-class UnknownPartError(KeyError):
-    """error raised when no handler is found for a Mandatory part"""
+class BundleValueError(ValueError):
+    """error raised when bundle2 cannot be processed
+
+    Current main usecase is unsupported part types."""
     pass
 
 class ReadOnlyPartError(RuntimeError):
@@ -307,7 +309,7 @@
                 if key != parttype: # mandatory parts
                     # todo:
                     # - use a more precise exception
-                    raise UnknownPartError(key)
+                    raise BundleValueError(key)
                 op.ui.debug('ignoring unknown advisory part %r\n' % key)
                 # consuming the part
                 part.read()
@@ -839,7 +841,7 @@
 @parthandler('b2x:error:unknownpart')
 def handlereplycaps(op, inpart):
     """Used to transmit unknown part error over the wire"""
-    raise UnknownPartError(inpart.params['parttype'])
+    raise BundleValueError(inpart.params['parttype'])
 
 @parthandler('b2x:error:pushraced')
 def handlereplycaps(op, inpart):
--- a/mercurial/exchange.py	Tue May 27 17:04:48 2014 -0500
+++ b/mercurial/exchange.py	Wed May 28 14:22:24 2014 -0700
@@ -224,11 +224,11 @@
     stream = util.chunkbuffer(bundler.getchunks())
     try:
         reply = pushop.remote.unbundle(stream, ['force'], 'push')
-    except bundle2.UnknownPartError, exc:
+    except bundle2.BundleValueError, exc:
         raise util.Abort('missing support for %s' % exc)
     try:
         op = bundle2.processbundle(pushop.repo, reply)
-    except bundle2.UnknownPartError, exc:
+    except bundle2.BundleValueError, exc:
         raise util.Abort('missing support for %s' % exc)
     cgreplies = op.records.getreplies(cgpart.id)
     assert len(cgreplies['changegroup']) == 1
@@ -554,7 +554,7 @@
     bundle = pullop.remote.getbundle('pull', **kwargs)
     try:
         op = bundle2.processbundle(pullop.repo, bundle, pullop.gettransaction)
-    except bundle2.UnknownPartError, exc:
+    except bundle2.BundleValueError, exc:
         raise util.Abort('missing support for %s' % exc)
 
     if pullop.fetch:
--- a/mercurial/wireproto.py	Tue May 27 17:04:48 2014 -0500
+++ b/mercurial/wireproto.py	Wed May 28 14:22:24 2014 -0700
@@ -803,7 +803,7 @@
         finally:
             fp.close()
             os.unlink(tempname)
-    except bundle2.UnknownPartError, exc:
+    except bundle2.BundleValueError, exc:
             bundler = bundle2.bundle20(repo.ui)
             bundler.newpart('B2X:ERROR:UNKNOWNPART', [('parttype', str(exc))])
             return streamres(bundler.getchunks())
--- a/tests/test-bundle2.t	Tue May 27 17:04:48 2014 -0500
+++ b/tests/test-bundle2.t	Wed May 28 14:22:24 2014 -0700
@@ -135,7 +135,7 @@
   >             unbundler = bundle2.unbundle20(ui, sys.stdin)
   >             op = bundle2.processbundle(repo, unbundler, lambda: tr)
   >             tr.close()
-  >         except KeyError, exc:
+  >         except bundle2.BundleValueError, exc:
   >             raise util.Abort('missing support for %s' % exc)
   >         except error.PushRaced, exc:
   >             raise util.Abort('push race: %s' % exc)
@@ -537,7 +537,7 @@
       Emana Karassoli, Loucra Loucra Ponponto, Pata Pata, Ko Ko Ko.
   debugreply: no reply
   0 unread bytes
-  abort: missing support for 'test:unknown'
+  abort: missing support for test:unknown
   [255]
 
 unbundle with a reply
@@ -1004,19 +1004,19 @@
   $ hg -R main push other -r e7ec4e813ba6
   pushing to other
   searching for changes
-  abort: missing support for 'test:unknown'
+  abort: missing support for test:unknown
   [255]
 
   $ hg -R main push ssh://user@dummy/other -r e7ec4e813ba6
   pushing to ssh://user@dummy/other
   searching for changes
-  abort: missing support for "'test:unknown'"
+  abort: missing support for test:unknown
   [255]
 
   $ hg -R main push http://localhost:$HGPORT2/ -r e7ec4e813ba6
   pushing to http://localhost:$HGPORT2/
   searching for changes
-  abort: missing support for "'test:unknown'"
+  abort: missing support for test:unknown
   [255]
 
 Doing the actual push: race