# HG changeset patch # User Pierre-Yves David # Date 2014-05-28 22:31:05 # Node ID 7568f5c1c80175dcb2ffd50f79c28cde5f1951bc # Parent 0cfda08afd2445ae2e7004ec414ad1e7849bcd2a bundle2: move exception classes into the error module Exceptions should have known their place. diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py --- a/mercurial/bundle2.py +++ b/mercurial/bundle2.py @@ -172,16 +172,6 @@ def _makefpartparamsizes(nbparams): """ return '>'+('BB'*nbparams) -class BundleValueError(ValueError): - """error raised when bundle2 cannot be processed - - Current main usecase is unsupported part types.""" - pass - -class ReadOnlyPartError(RuntimeError): - """error raised when code tries to alter a part being generated""" - pass - parthandlermapping = {} def parthandler(parttype): @@ -309,7 +299,7 @@ def processbundle(repo, unbundler, trans if key != parttype: # mandatory parts # todo: # - use a more precise exception - raise BundleValueError(key) + raise error.BundleValueError(key) op.ui.debug('ignoring unknown advisory part %r\n' % key) # consuming the part part.read() @@ -589,7 +579,7 @@ class bundlepart(object): # methods used to defines the part content def __setdata(self, data): if self._generated is not None: - raise ReadOnlyPartError('part is being generated') + raise error.ReadOnlyPartError('part is being generated') self._data = data def __getdata(self): return self._data @@ -607,7 +597,7 @@ class bundlepart(object): def addparam(self, name, value='', mandatory=True): if self._generated is not None: - raise ReadOnlyPartError('part is being generated') + raise error.ReadOnlyPartError('part is being generated') if name in self._seenparams: raise ValueError('duplicated params: %s' % name) self._seenparams.add(name) @@ -841,7 +831,7 @@ def handlereplycaps(op, inpart): @parthandler('b2x:error:unknownpart') def handlereplycaps(op, inpart): """Used to transmit unknown part error over the wire""" - raise BundleValueError(inpart.params['parttype']) + raise error.BundleValueError(inpart.params['parttype']) @parthandler('b2x:error:pushraced') def handlereplycaps(op, inpart): diff --git a/mercurial/error.py b/mercurial/error.py --- a/mercurial/error.py +++ b/mercurial/error.py @@ -98,3 +98,14 @@ class SignatureError(Exception): class PushRaced(RuntimeError): """An exception raised during unbundling that indicate a push race""" +# bundle2 related errors +class BundleValueError(ValueError): + """error raised when bundle2 cannot be processed + + Current main usecase is unsupported part types.""" + pass + +class ReadOnlyPartError(RuntimeError): + """error raised when code tries to alter a part being generated""" + pass + 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.BundleValueError, exc: + except error.BundleValueError, exc: raise util.Abort('missing support for %s' % exc) try: op = bundle2.processbundle(pushop.repo, reply) - except bundle2.BundleValueError, exc: + except error.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.BundleValueError, exc: + except error.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.BundleValueError, exc: + except error.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 bundle2.BundleValueError, exc: + > except error.BundleValueError, exc: > raise util.Abort('missing support for %s' % exc) > except error.PushRaced, exc: > raise util.Abort('push race: %s' % exc)