[PATCH 1 of 3 RFC STABLE] serve: log exceptions in error log

Mads Kiilerich mads at kiilerich.com
Sat Feb 19 20:58:29 CST 2011


Mads Kiilerich wrote, On 02/19/2011 03:18 AM:
> # HG changeset patch
> # User Mads Kiilerich<mads at kiilerich.com>
> # Date 1298081619 -3600
> # Branch stable
> # Node ID ff833ea575ee79d91cfa9cfe7e04d8937cff9d30
> # Parent  b366a5e021c6d8d1e3774d7829af2c0c74d2163c
> serve: log exceptions in error log
>
> The default error handler just printed exceptions but they did not appear when
> running in daemon mode.
>
> diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py
> --- a/mercurial/hgweb/server.py
> +++ b/mercurial/hgweb/server.py
> @@ -74,6 +74,10 @@
>               tb = "".join(traceback.format_exception(*sys.exc_info()))
>               self.log_error("Exception happened during processing "
>                              "request '%s':\n%s", self.path, tb)
> +        except Exception:
> +            tb = "".join(traceback.format_exception(*sys.exc_info()))
> +            self.log_error("Unhandled exception processing "
> +                           "request '%s':\n%s", self.path, tb)
>
>       def do_GET(self):
>           self.do_POST()

Nooo ...

I didn't dare to change the special handling of StandardError, but now I 
do. Why do we only catch StandardError here in do_POST? (Introduced by 
ThomasAH in 769be3c57564.)

I now think we should report Internal Error to the client no matter what 
and thus just need this simple fix:

--- a/mercurial/hgweb/server.py
+++ b/mercurial/hgweb/server.py
@@ -68,7 +68,7 @@
      def do_POST(self):
          try:
              self.do_write()
-        except StandardError:
+        except Exception:
              self._start_response("500 Internal Server Error", [])
              self._write("Internal Server Error")
              tb = "".join(traceback.format_exception(*sys.exc_info()))

Here be dragons???

/Mads



More information about the Mercurial-devel mailing list