Catch HTTPException when reading from remote http repository.
authorThomas Arendsen Hein <thomas@intevation.de>
Wed, 29 Mar 2006 12:45:33 +0200
changeset 2015 1a09814a5b1f
parent 2014 416f9e9e5f1b
child 2018 ea00c5705043
child 2019 ced2d3620f95
Catch HTTPException when reading from remote http repository. If the server dies very early, an httplib.IncompleteRead exception may be raised, because httplib can't read a single byte. Catching all HTTPException subclasses here will prevent ugly backtraces for similar things, too.
mercurial/httprepo.py
--- a/mercurial/httprepo.py	Tue Mar 28 09:26:38 2006 -0800
+++ b/mercurial/httprepo.py	Wed Mar 29 12:45:33 2006 +0200
@@ -9,7 +9,7 @@
 from remoterepo import *
 from i18n import gettext as _
 from demandload import *
-demandload(globals(), "hg os urllib urllib2 urlparse zlib util")
+demandload(globals(), "hg os urllib urllib2 urlparse zlib util httplib")
 
 class httprepository(remoterepository):
     def __init__(self, ui, path):
@@ -129,8 +129,11 @@
 
         def zgenerator(f):
             zd = zlib.decompressobj()
-            for chnk in f:
-                yield zd.decompress(chnk)
+            try:
+                for chnk in f:
+                    yield zd.decompress(chnk)
+            except httplib.HTTPException, inst:
+                raise IOError(None, _('connection ended unexpectedly'))
             yield zd.flush()
 
         return util.chunkbuffer(zgenerator(util.filechunkiter(f)))