changeset 6368:2c370f08c486

hgweb: better error messages
author Dirkjan Ochtman <dirkjan@ochtman.nl>
date Sun, 23 Mar 2008 23:08:18 +0100
parents 51984a2413f2
children 53912d30ac40
files mercurial/hgweb/hgweb_mod.py mercurial/hgweb/webcommands.py tests/test-hgweb tests/test-hgweb.out tests/test-hgwebdir.out
diffstat 5 files changed, 61 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/hgweb/hgweb_mod.py	Sun Mar 23 22:15:47 2008 +0100
+++ b/mercurial/hgweb/hgweb_mod.py	Sun Mar 23 23:08:18 2008 +0100
@@ -234,7 +234,7 @@
                 cmd = req.form['cmd'][0]
 
             if cmd not in webcommands.__all__:
-                msg = 'No such method: %s' % cmd
+                msg = 'no such method: %s' % cmd
                 raise ErrorResponse(HTTP_BAD_REQUEST, msg)
             elif cmd == 'file' and 'raw' in req.form.get('style', []):
                 self.ctype = ctype
@@ -248,7 +248,11 @@
 
         except revlog.LookupError, err:
             req.respond(HTTP_NOT_FOUND, ctype)
-            req.write(tmpl('error', error='revision not found: %s' % err.name))
+            if 'manifest' in err.message:
+                msg = str(err)
+            else:
+                msg = 'revision not found: %s' % err.name
+            req.write(tmpl('error', error=msg))
         except (RepoError, revlog.RevlogError), inst:
             req.respond(HTTP_SERVER_ERROR, ctype)
             req.write(tmpl('error', error=str(inst)))
@@ -737,7 +741,7 @@
                 files[short] = (f, n)
 
         if not files:
-            raise ErrorResponse(HTTP_NOT_FOUND, 'Path not found: ' + path)
+            raise ErrorResponse(HTTP_NOT_FOUND, 'path not found: ' + path)
 
         def filelist(**map):
             fl = files.keys()
--- a/mercurial/hgweb/webcommands.py	Sun Mar 23 22:15:47 2008 +0100
+++ b/mercurial/hgweb/webcommands.py	Sun Mar 23 23:08:18 2008 +0100
@@ -34,10 +34,13 @@
 
     try:
         fctx = web.filectx(req)
-    except revlog.LookupError:
-        content = web.manifest(tmpl, web.changectx(req), path)
-        req.respond(HTTP_OK, web.ctype)
-        return content
+    except revlog.LookupError, inst:
+        try:
+            content = web.manifest(tmpl, web.changectx(req), path)
+            req.respond(HTTP_OK, web.ctype)
+            return content
+        except ErrorResponse:
+            raise inst
 
     path = fctx.path()
     text = fctx.data()
@@ -53,10 +56,13 @@
     if path:
         try:
             return web.filerevision(tmpl, web.filectx(req))
-        except revlog.LookupError:
+        except revlog.LookupError, inst:
             pass
 
-    return web.manifest(tmpl, web.changectx(req), path)
+    try:
+        return web.manifest(tmpl, web.changectx(req), path)
+    except ErrorResponse:
+        raise inst
 
 def changelog(web, req, tmpl, shortlog = False):
     if 'node' in req.form:
@@ -109,7 +115,7 @@
         web.configbool("web", "allow" + type_, False))):
         web.archive(tmpl, req, req.form['node'][0], type_)
         return []
-    raise ErrorResponse(HTTP_NOT_FOUND, 'Unsupported archive type: %s' % type_)
+    raise ErrorResponse(HTTP_NOT_FOUND, 'unsupported archive type: %s' % type_)
 
 def static(web, req, tmpl):
     fname = req.form['file'][0]
--- a/tests/test-hgweb	Sun Mar 23 22:15:47 2008 +0100
+++ b/tests/test-hgweb	Sun Mar 23 23:08:18 2008 +0100
@@ -27,6 +27,8 @@
 
 echo % should give a 404 - file does not exist
 "$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/bork?style=raw'
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/file/tip/bork'
+"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/diff/tip/bork?style=raw'
 
 echo % stop and restart
 kill `cat hg.pid`
--- a/tests/test-hgweb.out	Sun Mar 23 22:15:47 2008 +0100
+++ b/tests/test-hgweb.out	Sun Mar 23 23:08:18 2008 +0100
@@ -59,14 +59,49 @@
 400
 
 
-error: No such method: spam
+error: no such method: spam
 % should give a 404 - file does not exist
 404 Not Found
 
 
-error: Path not found: bork/
+error: bork@2ef0ac749a14: not found in manifest
+404 Not Found
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+<head>
+<link rel="icon" href="/static/hgicon.png" type="image/png">
+<meta name="robots" content="index, nofollow" />
+<link rel="stylesheet" href="/static/style.css" type="text/css" />
+
+<title>Mercurial Error</title>
+</head>
+<body>
+
+<h2>Mercurial Error</h2>
+
+<p>
+An error occurred while processing your request:
+</p>
+<p>
+bork@2ef0ac749a14: not found in manifest
+</p>
+
+
+<div class="logo">
+<a href="http://www.selenic.com/mercurial/">
+<img src="/static/hglogo.png" width=75 height=90 border=0 alt="mercurial"></a>
+</div>
+
+</body>
+</html>
+
+404 Not Found
+
+
+error: bork@2ef0ac749a14: not found in manifest
 % stop and restart
-7 log lines written
+9 log lines written
 % static file
 200 Script output follows
 
--- a/tests/test-hgwebdir.out	Sun Mar 23 22:15:47 2008 +0100
+++ b/tests/test-hgwebdir.out	Sun Mar 23 23:08:18 2008 +0100
@@ -5,7 +5,7 @@
 404 Not Found
 
 
-error: Path not found: bork/
+error: bork@8580ff50825a: not found in manifest
 % should succeed
 200 Script output follows