Patchwork [STABLE] hgweb: returns 404 for unknow revision instead of 500

login
register
mail settings
Submitter Pierre-Yves David
Date Jan. 31, 2013, 9:34 p.m.
Message ID <916f042886d5b3900a64.1359668086@yamac.lan>
Download mbox | patch
Permalink /patch/776/
State Accepted
Commit 0af2fe7b32746fca5c5e5eebe923167606729b8d
Headers show

Comments

Pierre-Yves David - Jan. 31, 2013, 9:34 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
# Date 1359667852 -3600
# Branch stable
# Node ID 916f042886d5b3900a64fa116d6ac4369f92e279
# Parent  2a1fac3650a5b4d650198604c82ab59969500374
hgweb: returns 404 for unknow revision instead of 500

I noticed that access to filtered revision returned HTTP 500 code (internal
server error). Investigation shown that it was the case for unknown revision
too. That wrong and we now properly return a 404 for revision not found.
Matt Mackall - Feb. 1, 2013, 8:42 p.m.
On Thu, 2013-01-31 at 22:34 +0100, Pierre-Yves David wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david@ens-lyon.org>
> # Date 1359667852 -3600
> # Branch stable
> # Node ID 916f042886d5b3900a64fa116d6ac4369f92e279
> # Parent  2a1fac3650a5b4d650198604c82ab59969500374
> hgweb: returns 404 for unknow revision instead of 500

Queued for stable, thanks. We might want to examine whether adjusting
the class hierarchy makes sense here post-2.5.

Patch

diff --git a/mercurial/hgweb/hgweb_mod.py b/mercurial/hgweb/hgweb_mod.py
--- a/mercurial/hgweb/hgweb_mod.py
+++ b/mercurial/hgweb/hgweb_mod.py
@@ -229,14 +229,14 @@  class hgweb(object):
                 content = getattr(webcommands, cmd)(self, req, tmpl)
                 req.respond(HTTP_OK, ctype)
 
             return content
 
-        except error.LookupError, err:
+        except (error.LookupError, error.RepoLookupError), err:
             req.respond(HTTP_NOT_FOUND, ctype)
             msg = str(err)
-            if 'manifest' not in msg:
+            if util.safehasattr(err, 'name') and 'manifest' not in msg:
                 msg = 'revision not found: %s' % err.name
             return tmpl('error', error=msg)
         except (error.RepoError, error.RevlogError), inst:
             req.respond(HTTP_SERVER_ERROR, ctype)
             return tmpl('error', error=str(inst))
diff --git a/tests/test-hgweb-commands.t b/tests/test-hgweb-commands.t
--- a/tests/test-hgweb-commands.t
+++ b/tests/test-hgweb-commands.t
@@ -1398,6 +1398,35 @@  search works with filtering
   $ QUERY_STRING='rev=babar'
   $ python hgweb.cgi > search
   $ grep Status search
   Status: 200 Script output follows\r (esc)
 
+proper status for filtered revision
+
+
+(missing rev)
+
+  $ PATH_INFO=/rev/5; export PATH_INFO
+  $ QUERY_STRING='style=raw'
+  $ python hgweb.cgi #> search
+  Status: 404 Not Found\r (esc)
+  ETag: *\r (glob) (esc)
+  Content-Type: text/plain; charset=ascii\r (esc)
+  \r (esc)
+  
+  error: unknown revision '5'
+
+
+
+(filtered rev)
+
+  $ PATH_INFO=/rev/4; export PATH_INFO
+  $ QUERY_STRING='style=raw'
+  $ python hgweb.cgi #> search
+  Status: 404 Not Found\r (esc)
+  ETag: *\r (glob) (esc)
+  Content-Type: text/plain; charset=ascii\r (esc)
+  \r (esc)
+  
+  error: unknown revision '4'
+
   $ cd ..