Mercurial > hg
comparison mercurial/wireproto.py @ 24796:61ff209fc01d
bundle2: refactor error bundle creation for the wireprotocol
We want to add output information to the error bundle. Before doing this, we
rework the code to have a single bundler creation and return statement. This
will make the update with the output simpler as only one place will have to be
touched.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 16 Apr 2015 03:56:50 -0400 |
parents | 553dc2b094d9 |
children | 0c4d5e01b31f |
comparison
equal
deleted
inserted
replaced
24795:f9aa4cb8f2dd | 24796:61ff209fc01d |
---|---|
839 return pushres(r) | 839 return pushres(r) |
840 | 840 |
841 finally: | 841 finally: |
842 fp.close() | 842 fp.close() |
843 os.unlink(tempname) | 843 os.unlink(tempname) |
844 except error.BundleValueError, exc: | 844 |
845 bundler = bundle2.bundle20(repo.ui) | 845 except (error.BundleValueError, util.Abort, error.PushRaced), exc: |
846 # handle non-bundle2 case first | |
847 if not getattr(exc, 'duringunbundle2', False): | |
848 try: | |
849 raise | |
850 except util.Abort: | |
851 # The old code we moved used sys.stderr directly. | |
852 # We did not change it to minimise code change. | |
853 # This need to be moved to something proper. | |
854 # Feel free to do it. | |
855 sys.stderr.write("abort: %s\n" % exc) | |
856 return pushres(0) | |
857 except error.PushRaced: | |
858 return pusherr(str(exc)) | |
859 | |
860 bundler = bundle2.bundle20(repo.ui) | |
861 try: | |
862 raise | |
863 except error.BundleValueError, exc: | |
846 errpart = bundler.newpart('error:unsupportedcontent') | 864 errpart = bundler.newpart('error:unsupportedcontent') |
847 if exc.parttype is not None: | 865 if exc.parttype is not None: |
848 errpart.addparam('parttype', exc.parttype) | 866 errpart.addparam('parttype', exc.parttype) |
849 if exc.params: | 867 if exc.params: |
850 errpart.addparam('params', '\0'.join(exc.params)) | 868 errpart.addparam('params', '\0'.join(exc.params)) |
851 return streamres(bundler.getchunks()) | 869 except util.Abort, exc: |
852 except util.Abort, inst: | 870 manargs = [('message', str(exc))] |
853 # The old code we moved used sys.stderr directly. | |
854 # We did not change it to minimise code change. | |
855 # This need to be moved to something proper. | |
856 # Feel free to do it. | |
857 if getattr(inst, 'duringunbundle2', False): | |
858 bundler = bundle2.bundle20(repo.ui) | |
859 manargs = [('message', str(inst))] | |
860 advargs = [] | 871 advargs = [] |
861 if inst.hint is not None: | 872 if exc.hint is not None: |
862 advargs.append(('hint', inst.hint)) | 873 advargs.append(('hint', exc.hint)) |
863 bundler.addpart(bundle2.bundlepart('error:abort', | 874 bundler.addpart(bundle2.bundlepart('error:abort', |
864 manargs, advargs)) | 875 manargs, advargs)) |
865 return streamres(bundler.getchunks()) | 876 except error.PushRaced, exc: |
866 else: | |
867 sys.stderr.write("abort: %s\n" % inst) | |
868 return pushres(0) | |
869 except error.PushRaced, exc: | |
870 if getattr(exc, 'duringunbundle2', False): | |
871 bundler = bundle2.bundle20(repo.ui) | |
872 bundler.newpart('error:pushraced', [('message', str(exc))]) | 877 bundler.newpart('error:pushraced', [('message', str(exc))]) |
873 return streamres(bundler.getchunks()) | 878 return streamres(bundler.getchunks()) |
874 else: | |
875 return pusherr(str(exc)) |