changeset 21618:7568f5c1c801

bundle2: move exception classes into the error module Exceptions should have known their place.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Wed, 28 May 2014 15:31:05 -0700
parents 0cfda08afd24
children 292331e906d7
files mercurial/bundle2.py mercurial/error.py mercurial/exchange.py mercurial/wireproto.py tests/test-bundle2.t
diffstat 5 files changed, 20 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/bundle2.py	Wed May 28 14:22:24 2014 -0700
+++ b/mercurial/bundle2.py	Wed May 28 15:31:05 2014 -0700
@@ -172,16 +172,6 @@
     """
     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 @@
                 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 @@
     # 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 @@
 
     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 @@
 @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):
--- a/mercurial/error.py	Wed May 28 14:22:24 2014 -0700
+++ b/mercurial/error.py	Wed May 28 15:31:05 2014 -0700
@@ -98,3 +98,14 @@
 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
+
--- a/mercurial/exchange.py	Wed May 28 14:22:24 2014 -0700
+++ b/mercurial/exchange.py	Wed May 28 15:31:05 2014 -0700
@@ -224,11 +224,11 @@
     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 @@
     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:
--- a/mercurial/wireproto.py	Wed May 28 14:22:24 2014 -0700
+++ b/mercurial/wireproto.py	Wed May 28 15:31:05 2014 -0700
@@ -803,7 +803,7 @@
         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())
--- a/tests/test-bundle2.t	Wed May 28 14:22:24 2014 -0700
+++ b/tests/test-bundle2.t	Wed May 28 15:31:05 2014 -0700
@@ -135,7 +135,7 @@
   >             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)