# HG changeset patch # User Pierre-Yves David # Date 2014-05-28 21:22:24 # Node ID 0cfda08afd2445ae2e7004ec414ad1e7849bcd2a # Parent 0a8e7f81e8ae199d75241755534038f8201ae12c 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. diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -172,8 +172,10 @@ def _makefpartparamsizes(nbparams): """ 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 @@ def processbundle(repo, unbundler, trans 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 @@ def handlereplycaps(op, inpart): @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): diff --git a/mercurial/exchange.py b/mercurial/exchange.py --- a/mercurial/exchange.py +++ b/mercurial/exchange.py @@ -224,11 +224,11 @@ def _pushbundle2(pushop): 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 @@ def _pullbundle2(pullop): 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: diff --git a/mercurial/wireproto.py b/mercurial/wireproto.py --- a/mercurial/wireproto.py +++ b/mercurial/wireproto.py @@ -803,7 +803,7 @@ def unbundle(repo, proto, heads): 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()) diff --git a/tests/test-bundle2.t b/tests/test-bundle2.t --- a/tests/test-bundle2.t +++ b/tests/test-bundle2.t @@ -135,7 +135,7 @@ Create an extension to test bundle2 API > 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 @@ Unbundle with an unknown mandatory part 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 @@ Doing the actual push: unknown mandatory $ 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