# HG changeset patch # User Thomas Arendsen Hein # Date 1161965832 -7200 # Node ID eda9e7c9300d599572d83bcf0dcbc6c25b2d4996 # Parent db946221a58adb888b250dda50e4b1338244ec2c 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. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -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: diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -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): diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -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