wireproto: properly report server Abort during 'getbundle' stable
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Fri, 10 Feb 2017 18:20:58 +0100
branchstable
changeset 35803 f3807a135e43b0499db12dc79697e0b9589dd095
parent 35802 d70971a3ae80fbebdca7a0e3adb72370f08f60e1
child 35804 aa25989b0658dcefbd4c1bce7c389f006f22af30
child 35805 455677a7667f6658be5c6e3f3d7b81a29cf5f9a2
push id460
push usergszorc@mozilla.com
push dateThu, 16 Feb 2017 05:23:57 +0000
wireproto: properly report server Abort during 'getbundle' Previously Abort raised during 'getbundle' call poorly reported (HTTP-500 for http, some scary messages for ssh). Abort error have been properly reported for "push" for a long time, there is not reason to be different for 'getbundle'. We properly catch such error and report them back the best way available. For bundle, we issue a valid bundle2 reply (as expected by the client) with an 'error:abort' part. With bundle1 we do as best as we can depending of http or ssh.
mercurial/wireproto.py
tests/crashgetbundler.py
tests/test-http-bundle1.t
tests/test-http.t
tests/test-ssh-bundle1.t
tests/test-ssh.t
--- a/mercurial/wireproto.py
+++ b/mercurial/wireproto.py
@@ -834,17 +834,34 @@ def getbundle(repo, proto, others):
 
     if not bundle1allowed(repo, 'pull'):
         if not exchange.bundle2requested(opts.get('bundlecaps')):
             if proto.name == 'http':
                 return ooberror(bundle2required)
             raise error.Abort(bundle2requiredmain,
                               hint=bundle2requiredhint)
 
-    chunks = exchange.getbundlechunks(repo, 'serve', **opts)
+    #chunks = exchange.getbundlechunks(repo, 'serve', **opts)
+    try:
+        chunks = exchange.getbundlechunks(repo, 'serve', **opts)
+    except error.Abort as exc:
+        # cleanly forward Abort error to the client
+        if not exchange.bundle2requested(opts.get('bundlecaps')):
+            if proto.name == 'http':
+                return ooberror(str(exc) + '\n')
+            raise # cannot do better for bundle1 + ssh
+        # bundle2 request expect a bundle2 reply
+        bundler = bundle2.bundle20(repo.ui)
+        manargs = [('message', str(exc))]
+        advargs = []
+        if exc.hint is not None:
+            advargs.append(('hint', exc.hint))
+        bundler.addpart(bundle2.bundlepart('error:abort',
+                                           manargs, advargs))
+        return streamres(gen=bundler.getchunks(), v1compressible=True)
     return streamres(gen=chunks, v1compressible=True)
 
 @wireprotocommand('heads')
 def heads(repo, proto):
     h = repo.heads()
     return encodelist(h) + "\n"
 
 @wireprotocommand('hello')
new file mode 100644
--- /dev/null
+++ b/tests/crashgetbundler.py
@@ -0,0 +1,14 @@
+from __future__ import absolute_import
+
+from mercurial.i18n import _
+from mercurial import (
+        changegroup,
+        error,
+        extensions
+    )
+
+def abort(orig, *args, **kwargs):
+    raise error.Abort(_('this is an exercise'))
+
+def uisetup(ui):
+    extensions.wrapfunction(changegroup, 'getbundler', abort)
--- a/tests/test-http-bundle1.t
+++ b/tests/test-http-bundle1.t
@@ -328,8 +328,20 @@ clone of serve with repo in root and uns
   added 3 changesets with 7 changes to 7 files
   updating to branch default
   abort: HTTP Error 404: Not Found
   [255]
 
 check error log
 
   $ cat error.log
+
+Check error reporting while pulling/cloning
+
+  $ $RUNTESTDIR/killdaemons.py
+  $ hg -R test serve -p $HGPORT -d --pid-file=hg3.pid -E error.log --config extensions.crash=${TESTDIR}/crashgetbundler.py
+  $ cat hg3.pid >> $DAEMON_PIDS
+  $ hg clone http://localhost:$HGPORT/ abort-clone
+  requesting all changes
+  abort: remote error:
+  this is an exercise
+  [255]
+  $ cat error.log
--- a/tests/test-http.t
+++ b/tests/test-http.t
@@ -316,8 +316,20 @@ clone of serve with repo in root and uns
   added 3 changesets with 7 changes to 7 files
   updating to branch default
   abort: HTTP Error 404: Not Found
   [255]
 
 check error log
 
   $ cat error.log
+
+check abort error reporting while pulling/cloning
+
+  $ $RUNTESTDIR/killdaemons.py
+  $ hg -R test serve -p $HGPORT -d --pid-file=hg3.pid -E error.log --config extensions.crash=${TESTDIR}/crashgetbundler.py
+  $ cat hg3.pid >> $DAEMON_PIDS
+  $ hg clone http://localhost:$HGPORT/ abort-clone
+  requesting all changes
+  remote: abort: this is an exercise
+  abort: pull failed on remote
+  [255]
+  $ cat error.log
--- a/tests/test-ssh-bundle1.t
+++ b/tests/test-ssh-bundle1.t
@@ -538,8 +538,25 @@ remote hook failure is attributed to rem
   remote: adding file changes
   remote: added 1 changesets with 1 changes to 1 files
   remote: hook failure!
   remote: transaction abort!
   remote: rollback completed
   remote: abort: pretxnchangegroup.fail hook failed
   [1]
 
+abort during pull is properly reported as such
+
+  $ echo morefoo >> ../remote/foo
+  $ hg -R ../remote commit --message "more foo to be pulled"
+  $ cat >> ../remote/.hg/hgrc << EOF
+  > [extensions]
+  > crash = ${TESTDIR}/crashgetbundler.py
+  > EOF
+  $ hg --config ui.ssh="python $TESTDIR/dummyssh" pull
+  pulling from ssh://user@dummy/remote
+  searching for changes
+  adding changesets
+  remote: abort: this is an exercise
+  transaction abort!
+  rollback completed
+  abort: stream ended unexpectedly (got 0 bytes, expected 4)
+  [255]
--- a/tests/test-ssh.t
+++ b/tests/test-ssh.t
@@ -543,8 +543,22 @@ remote hook failure is attributed to rem
   remote: added 1 changesets with 1 changes to 1 files
   remote: hook failure!
   remote: transaction abort!
   remote: rollback completed
   remote: pretxnchangegroup.fail hook failed
   abort: push failed on remote
   [255]
 
+abort during pull is properly reported as such
+
+  $ echo morefoo >> ../remote/foo
+  $ hg -R ../remote commit --message "more foo to be pulled"
+  $ cat >> ../remote/.hg/hgrc << EOF
+  > [extensions]
+  > crash = ${TESTDIR}/crashgetbundler.py
+  > EOF
+  $ hg --config ui.ssh="python $TESTDIR/dummyssh" pull
+  pulling from ssh://user@dummy/remote
+  searching for changes
+  remote: abort: this is an exercise
+  abort: pull failed on remote
+  [255]