diff mercurial/hgweb/protocol.py @ 6926:57b954d8d003

hgweb: raise ErrorResponses to communicate protocol errors
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Tue, 22 Jul 2008 18:23:20 +0200
parents 87abfefafe02
children a42d27bc809d
line wrap: on
line diff
--- a/mercurial/hgweb/protocol.py	Fri Aug 15 13:25:57 2008 +0200
+++ b/mercurial/hgweb/protocol.py	Tue Jul 22 18:23:20 2008 +0200
@@ -108,7 +108,6 @@
 
 def unbundle(repo, req):
 
-    errorfmt = '0\n%s\n'
     proto = req.env.get('wsgi.url_scheme') or 'http'
     their_heads = req.form['heads'][0].split(' ')
 
@@ -123,10 +122,7 @@
             # drain incoming bundle, else client will not see
             # response when run outside cgi script
             pass
-        req.respond(HTTP_OK, HGTYPE)
-        return errorfmt % 'unsynced changes',
-
-    req.respond(HTTP_OK, HGTYPE)
+        raise ErrorResponse(HTTP_OK, 'unsynced changes')
 
     # do not lock repo until all changegroup data is
     # streamed. save to temporary file.
@@ -142,7 +138,7 @@
             lock = repo.lock()
             try:
                 if not check_heads():
-                    return errorfmt % 'unsynced changes',
+                    raise ErrorResponse(HTTP_OK, 'unsynced changes')
 
                 fp.seek(0)
                 header = fp.read(6)
@@ -168,11 +164,12 @@
                 finally:
                     val = sys.stdout.getvalue()
                     sys.stdout, sys.stderr = oldio
+                req.respond(HTTP_OK, HGTYPE)
                 return '%d\n%s' % (ret, val),
             finally:
                 del lock
         except ValueError, inst:
-            return errorfmt % inst,
+            raise ErrorResponse(HTTP_OK, inst)
         except (OSError, IOError), inst:
             filename = getattr(inst, 'filename', '')
             # Don't send our filesystem layout to the client
@@ -185,8 +182,7 @@
                 code = HTTP_NOT_FOUND
             else:
                 code = HTTP_SERVER_ERROR
-            req.respond(code)
-            return '0\n%s: %s\n' % (error, filename),
+            raise ErrorResponse(code, '%s: %s' % (error, filename))
     finally:
         fp.close()
         os.unlink(tempname)