Mercurial > public > mercurial-scm > hg
comparison mercurial/exchange.py @ 41704:3b0ba4575c8c
exchange: raise error.Abort instead of ValueError
Raising ValueError results in an uncaught exception and a traceback
being printed. In the context of servers, it can result in an HTTP
500 and an exception being logged in the error log.
I don't think this is proper behavior.
The bundle2 code paths have a mechanism for translating an
error.Abort into an error message reported to the clients. I
think we should use that instead.
This commit replaces some ValueError with Abort so that
servers can error more gracefully.
Differential Revision: https://phab.mercurial-scm.org/D5972
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Fri, 15 Feb 2019 11:31:17 -0800 |
parents | 876494fd967d |
children | aaad36b88298 |
comparison
equal
deleted
inserted
replaced
41703:47c4ac5035a6 | 41704:3b0ba4575c8c |
---|---|
918 if cgversions: # 3.1 and 3.2 ship with an empty value | 918 if cgversions: # 3.1 and 3.2 ship with an empty value |
919 cgversions = [v for v in cgversions | 919 cgversions = [v for v in cgversions |
920 if v in changegroup.supportedoutgoingversions( | 920 if v in changegroup.supportedoutgoingversions( |
921 pushop.repo)] | 921 pushop.repo)] |
922 if not cgversions: | 922 if not cgversions: |
923 raise ValueError(_('no common changegroup version')) | 923 raise error.Abort(_('no common changegroup version')) |
924 version = max(cgversions) | 924 version = max(cgversions) |
925 cgstream = changegroup.makestream(pushop.repo, pushop.outgoing, version, | 925 cgstream = changegroup.makestream(pushop.repo, pushop.outgoing, version, |
926 'push') | 926 'push') |
927 cgpart = bundler.newpart('changegroup', data=cgstream) | 927 cgpart = bundler.newpart('changegroup', data=cgstream) |
928 if cgversions: | 928 if cgversions: |
2182 cgversions = b2caps.get('changegroup') | 2182 cgversions = b2caps.get('changegroup') |
2183 if cgversions: # 3.1 and 3.2 ship with an empty value | 2183 if cgversions: # 3.1 and 3.2 ship with an empty value |
2184 cgversions = [v for v in cgversions | 2184 cgversions = [v for v in cgversions |
2185 if v in changegroup.supportedoutgoingversions(repo)] | 2185 if v in changegroup.supportedoutgoingversions(repo)] |
2186 if not cgversions: | 2186 if not cgversions: |
2187 raise ValueError(_('no common changegroup version')) | 2187 raise error.Abort(_('no common changegroup version')) |
2188 version = max(cgversions) | 2188 version = max(cgversions) |
2189 | 2189 |
2190 outgoing = _computeoutgoing(repo, heads, common) | 2190 outgoing = _computeoutgoing(repo, heads, common) |
2191 if not outgoing.missing: | 2191 if not outgoing.missing: |
2192 return | 2192 return |
2226 b2caps=None, **kwargs): | 2226 b2caps=None, **kwargs): |
2227 """add a bookmark part to the requested bundle""" | 2227 """add a bookmark part to the requested bundle""" |
2228 if not kwargs.get(r'bookmarks', False): | 2228 if not kwargs.get(r'bookmarks', False): |
2229 return | 2229 return |
2230 if 'bookmarks' not in b2caps: | 2230 if 'bookmarks' not in b2caps: |
2231 raise ValueError(_('no common bookmarks exchange method')) | 2231 raise error.Abort(_('no common bookmarks exchange method')) |
2232 books = bookmod.listbinbookmarks(repo) | 2232 books = bookmod.listbinbookmarks(repo) |
2233 data = bookmod.binaryencode(books) | 2233 data = bookmod.binaryencode(books) |
2234 if data: | 2234 if data: |
2235 bundler.newpart('bookmarks', data=data) | 2235 bundler.newpart('bookmarks', data=data) |
2236 | 2236 |
2261 def _getbundlephasespart(bundler, repo, source, bundlecaps=None, | 2261 def _getbundlephasespart(bundler, repo, source, bundlecaps=None, |
2262 b2caps=None, heads=None, **kwargs): | 2262 b2caps=None, heads=None, **kwargs): |
2263 """add phase heads part to the requested bundle""" | 2263 """add phase heads part to the requested bundle""" |
2264 if kwargs.get(r'phases', False): | 2264 if kwargs.get(r'phases', False): |
2265 if not 'heads' in b2caps.get('phases'): | 2265 if not 'heads' in b2caps.get('phases'): |
2266 raise ValueError(_('no common phases exchange method')) | 2266 raise error.Abort(_('no common phases exchange method')) |
2267 if heads is None: | 2267 if heads is None: |
2268 heads = repo.heads() | 2268 heads = repo.heads() |
2269 | 2269 |
2270 headsbyphase = collections.defaultdict(set) | 2270 headsbyphase = collections.defaultdict(set) |
2271 if repo.publishing(): | 2271 if repo.publishing(): |