comparison mercurial/bundle2.py @ 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 f221eb0531d9
children 7568f5c1c801
comparison
equal deleted inserted replaced
21616:0a8e7f81e8ae 21617:0cfda08afd24
170 The number parameters is variable so we need to build that format 170 The number parameters is variable so we need to build that format
171 dynamically. 171 dynamically.
172 """ 172 """
173 return '>'+('BB'*nbparams) 173 return '>'+('BB'*nbparams)
174 174
175 class UnknownPartError(KeyError): 175 class BundleValueError(ValueError):
176 """error raised when no handler is found for a Mandatory part""" 176 """error raised when bundle2 cannot be processed
177
178 Current main usecase is unsupported part types."""
177 pass 179 pass
178 180
179 class ReadOnlyPartError(RuntimeError): 181 class ReadOnlyPartError(RuntimeError):
180 """error raised when code tries to alter a part being generated""" 182 """error raised when code tries to alter a part being generated"""
181 pass 183 pass
305 op.ui.debug('found a handler for part %r\n' % parttype) 307 op.ui.debug('found a handler for part %r\n' % parttype)
306 except KeyError: 308 except KeyError:
307 if key != parttype: # mandatory parts 309 if key != parttype: # mandatory parts
308 # todo: 310 # todo:
309 # - use a more precise exception 311 # - use a more precise exception
310 raise UnknownPartError(key) 312 raise BundleValueError(key)
311 op.ui.debug('ignoring unknown advisory part %r\n' % key) 313 op.ui.debug('ignoring unknown advisory part %r\n' % key)
312 # consuming the part 314 # consuming the part
313 part.read() 315 part.read()
314 continue 316 continue
315 317
837 raise util.Abort(inpart.params['message'], hint=inpart.params.get('hint')) 839 raise util.Abort(inpart.params['message'], hint=inpart.params.get('hint'))
838 840
839 @parthandler('b2x:error:unknownpart') 841 @parthandler('b2x:error:unknownpart')
840 def handlereplycaps(op, inpart): 842 def handlereplycaps(op, inpart):
841 """Used to transmit unknown part error over the wire""" 843 """Used to transmit unknown part error over the wire"""
842 raise UnknownPartError(inpart.params['parttype']) 844 raise BundleValueError(inpart.params['parttype'])
843 845
844 @parthandler('b2x:error:pushraced') 846 @parthandler('b2x:error:pushraced')
845 def handlereplycaps(op, inpart): 847 def handlereplycaps(op, inpart):
846 """Used to transmit push race error over the wire""" 848 """Used to transmit push race error over the wire"""
847 raise error.ResponseError(_('push failed:'), inpart.params['message']) 849 raise error.ResponseError(_('push failed:'), inpart.params['message'])