mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 07:17:55 +03:00
New UnexpectedOutput exception to catch server errors in localrepo.stream_in
If the unexpected is a string, the empty string will be mentioned, and long strings are cut to at most 400 chars.
This commit is contained in:
parent
46a2065971
commit
a0477d89a5
@ -3522,6 +3522,15 @@ def dispatch(args):
|
||||
u.warn(_("abort: %s: %s\n") % (inst.strerror, inst.filename))
|
||||
else:
|
||||
u.warn(_("abort: %s\n") % inst.strerror)
|
||||
except util.UnexpectedOutput, inst:
|
||||
u.warn(_("abort: %s") % inst[0])
|
||||
if not isinstance(inst[1], basestring):
|
||||
u.warn(" %r\n" % (inst[1],))
|
||||
elif not inst[1]:
|
||||
u.warn(_(" empty string\n"))
|
||||
else:
|
||||
u.warn("\n%r%s\n" %
|
||||
(inst[1][:400], len(inst[1]) > 400 and '...' or ''))
|
||||
except util.Abort, inst:
|
||||
u.warn(_("abort: %s\n") % inst)
|
||||
except TypeError, inst:
|
||||
|
@ -1783,17 +1783,32 @@ class localrepository(repo.repository):
|
||||
|
||||
def stream_in(self, remote):
|
||||
fp = remote.stream_out()
|
||||
resp = int(fp.readline())
|
||||
l = fp.readline()
|
||||
try:
|
||||
resp = int(l)
|
||||
except ValueError:
|
||||
raise util.UnexpectedOutput(
|
||||
_('Unexpected response from remote server:'), l)
|
||||
if resp != 0:
|
||||
raise util.Abort(_('operation forbidden by server'))
|
||||
self.ui.status(_('streaming all changes\n'))
|
||||
total_files, total_bytes = map(int, fp.readline().split(' ', 1))
|
||||
l = fp.readline()
|
||||
try:
|
||||
total_files, total_bytes = map(int, l.split(' ', 1))
|
||||
except ValueError, TypeError:
|
||||
raise util.UnexpectedOutput(
|
||||
_('Unexpected response from remote server:'), l)
|
||||
self.ui.status(_('%d files to transfer, %s of data\n') %
|
||||
(total_files, util.bytecount(total_bytes)))
|
||||
start = time.time()
|
||||
for i in xrange(total_files):
|
||||
name, size = fp.readline().split('\0', 1)
|
||||
size = int(size)
|
||||
l = fp.readline()
|
||||
try:
|
||||
name, size = l.split('\0', 1)
|
||||
size = int(size)
|
||||
except ValueError, TypeError:
|
||||
raise util.UnexpectedOutput(
|
||||
_('Unexpected response from remote server:'), l)
|
||||
self.ui.debug('adding %s (%s)\n' % (name, util.bytecount(size)))
|
||||
ofp = self.sopener(name, 'w')
|
||||
for chunk in util.filechunkiter(fp, limit=size):
|
||||
|
@ -136,6 +136,9 @@ def unique(g):
|
||||
class Abort(Exception):
|
||||
"""Raised if a command needs to print an error and exit."""
|
||||
|
||||
class UnexpectedOutput(Abort):
|
||||
"""Raised to print an error with part of output and exit."""
|
||||
|
||||
def always(fn): return True
|
||||
def never(fn): return False
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user