diff mercurial/wireproto.py @ 21177:952af771bc17 stable

bundle2: gracefully handle abort during unbundle Clients expect a bundle2 reply to their bundle2 submission. So we catch the Abort error and turn it into a bundle2 containing a part transporting the exception data. The unbundling of this reply will raise the error again.
author Pierre-Yves David <pierre-yves.david@fb.com>
date Mon, 21 Apr 2014 15:48:52 -0700
parents 60ad2ea5b106
children 4345274adc4b
line wrap: on
line diff
--- a/mercurial/wireproto.py	Tue Apr 22 11:22:41 2014 -0700
+++ b/mercurial/wireproto.py	Mon Apr 21 15:48:52 2014 -0700
@@ -808,7 +808,17 @@
         # We did not change it to minimise code change.
         # This need to be moved to something proper.
         # Feel free to do it.
-        sys.stderr.write("abort: %s\n" % inst)
-        return pushres(0)
+        if getattr(inst, 'duringunbundle2', False):
+            bundler = bundle2.bundle20(repo.ui)
+            manargs = [('message', str(inst))]
+            advargs = []
+            if inst.hint is not None:
+                advargs.append(('hint', inst.hint))
+            bundler.addpart(bundle2.bundlepart('B2X:ERROR:ABORT',
+                                               manargs, advargs))
+            return streamres(bundler.getchunks())
+        else:
+            sys.stderr.write("abort: %s\n" % inst)
+            return pushres(0)
     except exchange.PushRaced, exc:
         return pusherr(str(exc))