##// END OF EJS Templates
bundle2: move exception classes into the error module...
Pierre-Yves David -
r21618:7568f5c1 default
parent child Browse files
Show More
@@ -172,16 +172,6 b' def _makefpartparamsizes(nbparams):'
172 """
172 """
173 return '>'+('BB'*nbparams)
173 return '>'+('BB'*nbparams)
174
174
175 class BundleValueError(ValueError):
176 """error raised when bundle2 cannot be processed
177
178 Current main usecase is unsupported part types."""
179 pass
180
181 class ReadOnlyPartError(RuntimeError):
182 """error raised when code tries to alter a part being generated"""
183 pass
184
185 parthandlermapping = {}
175 parthandlermapping = {}
186
176
187 def parthandler(parttype):
177 def parthandler(parttype):
@@ -309,7 +299,7 b' def processbundle(repo, unbundler, trans'
309 if key != parttype: # mandatory parts
299 if key != parttype: # mandatory parts
310 # todo:
300 # todo:
311 # - use a more precise exception
301 # - use a more precise exception
312 raise BundleValueError(key)
302 raise error.BundleValueError(key)
313 op.ui.debug('ignoring unknown advisory part %r\n' % key)
303 op.ui.debug('ignoring unknown advisory part %r\n' % key)
314 # consuming the part
304 # consuming the part
315 part.read()
305 part.read()
@@ -589,7 +579,7 b' class bundlepart(object):'
589 # methods used to defines the part content
579 # methods used to defines the part content
590 def __setdata(self, data):
580 def __setdata(self, data):
591 if self._generated is not None:
581 if self._generated is not None:
592 raise ReadOnlyPartError('part is being generated')
582 raise error.ReadOnlyPartError('part is being generated')
593 self._data = data
583 self._data = data
594 def __getdata(self):
584 def __getdata(self):
595 return self._data
585 return self._data
@@ -607,7 +597,7 b' class bundlepart(object):'
607
597
608 def addparam(self, name, value='', mandatory=True):
598 def addparam(self, name, value='', mandatory=True):
609 if self._generated is not None:
599 if self._generated is not None:
610 raise ReadOnlyPartError('part is being generated')
600 raise error.ReadOnlyPartError('part is being generated')
611 if name in self._seenparams:
601 if name in self._seenparams:
612 raise ValueError('duplicated params: %s' % name)
602 raise ValueError('duplicated params: %s' % name)
613 self._seenparams.add(name)
603 self._seenparams.add(name)
@@ -841,7 +831,7 b' def handlereplycaps(op, inpart):'
841 @parthandler('b2x:error:unknownpart')
831 @parthandler('b2x:error:unknownpart')
842 def handlereplycaps(op, inpart):
832 def handlereplycaps(op, inpart):
843 """Used to transmit unknown part error over the wire"""
833 """Used to transmit unknown part error over the wire"""
844 raise BundleValueError(inpart.params['parttype'])
834 raise error.BundleValueError(inpart.params['parttype'])
845
835
846 @parthandler('b2x:error:pushraced')
836 @parthandler('b2x:error:pushraced')
847 def handlereplycaps(op, inpart):
837 def handlereplycaps(op, inpart):
@@ -98,3 +98,14 b' class SignatureError(Exception):'
98 class PushRaced(RuntimeError):
98 class PushRaced(RuntimeError):
99 """An exception raised during unbundling that indicate a push race"""
99 """An exception raised during unbundling that indicate a push race"""
100
100
101 # bundle2 related errors
102 class BundleValueError(ValueError):
103 """error raised when bundle2 cannot be processed
104
105 Current main usecase is unsupported part types."""
106 pass
107
108 class ReadOnlyPartError(RuntimeError):
109 """error raised when code tries to alter a part being generated"""
110 pass
111
@@ -224,11 +224,11 b' def _pushbundle2(pushop):'
224 stream = util.chunkbuffer(bundler.getchunks())
224 stream = util.chunkbuffer(bundler.getchunks())
225 try:
225 try:
226 reply = pushop.remote.unbundle(stream, ['force'], 'push')
226 reply = pushop.remote.unbundle(stream, ['force'], 'push')
227 except bundle2.BundleValueError, exc:
227 except error.BundleValueError, exc:
228 raise util.Abort('missing support for %s' % exc)
228 raise util.Abort('missing support for %s' % exc)
229 try:
229 try:
230 op = bundle2.processbundle(pushop.repo, reply)
230 op = bundle2.processbundle(pushop.repo, reply)
231 except bundle2.BundleValueError, exc:
231 except error.BundleValueError, exc:
232 raise util.Abort('missing support for %s' % exc)
232 raise util.Abort('missing support for %s' % exc)
233 cgreplies = op.records.getreplies(cgpart.id)
233 cgreplies = op.records.getreplies(cgpart.id)
234 assert len(cgreplies['changegroup']) == 1
234 assert len(cgreplies['changegroup']) == 1
@@ -554,7 +554,7 b' def _pullbundle2(pullop):'
554 bundle = pullop.remote.getbundle('pull', **kwargs)
554 bundle = pullop.remote.getbundle('pull', **kwargs)
555 try:
555 try:
556 op = bundle2.processbundle(pullop.repo, bundle, pullop.gettransaction)
556 op = bundle2.processbundle(pullop.repo, bundle, pullop.gettransaction)
557 except bundle2.BundleValueError, exc:
557 except error.BundleValueError, exc:
558 raise util.Abort('missing support for %s' % exc)
558 raise util.Abort('missing support for %s' % exc)
559
559
560 if pullop.fetch:
560 if pullop.fetch:
@@ -803,7 +803,7 b' def unbundle(repo, proto, heads):'
803 finally:
803 finally:
804 fp.close()
804 fp.close()
805 os.unlink(tempname)
805 os.unlink(tempname)
806 except bundle2.BundleValueError, exc:
806 except error.BundleValueError, exc:
807 bundler = bundle2.bundle20(repo.ui)
807 bundler = bundle2.bundle20(repo.ui)
808 bundler.newpart('B2X:ERROR:UNKNOWNPART', [('parttype', str(exc))])
808 bundler.newpart('B2X:ERROR:UNKNOWNPART', [('parttype', str(exc))])
809 return streamres(bundler.getchunks())
809 return streamres(bundler.getchunks())
@@ -135,7 +135,7 b' Create an extension to test bundle2 API'
135 > unbundler = bundle2.unbundle20(ui, sys.stdin)
135 > unbundler = bundle2.unbundle20(ui, sys.stdin)
136 > op = bundle2.processbundle(repo, unbundler, lambda: tr)
136 > op = bundle2.processbundle(repo, unbundler, lambda: tr)
137 > tr.close()
137 > tr.close()
138 > except bundle2.BundleValueError, exc:
138 > except error.BundleValueError, exc:
139 > raise util.Abort('missing support for %s' % exc)
139 > raise util.Abort('missing support for %s' % exc)
140 > except error.PushRaced, exc:
140 > except error.PushRaced, exc:
141 > raise util.Abort('push race: %s' % exc)
141 > raise util.Abort('push race: %s' % exc)
General Comments 0
You need to be logged in to leave comments. Login now