# HG changeset patch # User Pierre-Yves David # Date 1401317479 25200 # Node ID 6eaa71b2a3cca686aa4d47909171d1c208a810e6 # Parent 292331e906d7b91aaf9c8b5a9207790fe05cdcc1 bundle2: introduce a parttype attribute to BundleValueError We will use the Exception for more that just unknown part type. diff -r 292331e906d7 -r 6eaa71b2a3cc mercurial/bundle2.py --- a/mercurial/bundle2.py Tue May 27 10:32:07 2014 -0700 +++ b/mercurial/bundle2.py Wed May 28 15:51:19 2014 -0700 @@ -299,7 +299,7 @@ if key != parttype: # mandatory parts # todo: # - use a more precise exception - raise error.BundleValueError(key) + raise error.BundleValueError(parttype=key) op.ui.debug('ignoring unknown advisory part %r\n' % key) # consuming the part part.read() @@ -831,7 +831,8 @@ @parthandler('b2x:error:unsupportedcontent') def handlereplycaps(op, inpart): """Used to transmit unknown content error over the wire""" - raise error.BundleValueError(inpart.params['parttype']) + parttype = inpart.params['parttype'] + raise error.BundleValueError(parttype=parttype) @parthandler('b2x:error:pushraced') def handlereplycaps(op, inpart): diff -r 292331e906d7 -r 6eaa71b2a3cc mercurial/error.py --- a/mercurial/error.py Tue May 27 10:32:07 2014 -0700 +++ b/mercurial/error.py Wed May 28 15:51:19 2014 -0700 @@ -103,7 +103,10 @@ """error raised when bundle2 cannot be processed Current main usecase is unsupported part types.""" - pass + + def __init__(self, parttype): + self.parttype = parttype + super(BundleValueError, self).__init__(parttype) class ReadOnlyPartError(RuntimeError): """error raised when code tries to alter a part being generated""" diff -r 292331e906d7 -r 6eaa71b2a3cc mercurial/wireproto.py --- a/mercurial/wireproto.py Tue May 27 10:32:07 2014 -0700 +++ b/mercurial/wireproto.py Wed May 28 15:51:19 2014 -0700 @@ -806,7 +806,7 @@ except error.BundleValueError, exc: bundler = bundle2.bundle20(repo.ui) errpart = bundler.newpart('B2X:ERROR:UNSUPPORTEDCONTENT') - errpart.addparam('parttype', str(exc)) + errpart.addparam('parttype', exc.parttype) return streamres(bundler.getchunks()) except util.Abort, inst: # The old code we moved used sys.stderr directly.