diff hgext/lfs/wireprotolfsserver.py @ 37690:726c4102db9e

lfs: log information about Internal Server Errors reported in the Batch API Reporting a 500 and then not leaving any traces on the server seems like a receipe for frustration. There's similar log writing in hgweb.server.do_POST(). That doesn't write directly to the wsgi.errors object, so it doesn't seem worth trying to refactor. It does seem like earlier stack frames are missing for some reason.
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 13 Apr 2018 12:39:54 -0400
parents b03f2e0fdb88
children 10e5bb9678f4
line wrap: on
line diff
--- a/hgext/lfs/wireprotolfsserver.py	Sat Apr 07 12:48:21 2018 -0400
+++ b/hgext/lfs/wireprotolfsserver.py	Fri Apr 13 12:39:54 2018 -0400
@@ -10,6 +10,7 @@
 import datetime
 import errno
 import json
+import traceback
 
 from mercurial.hgweb import (
     common as hgwebcommon,
@@ -63,6 +64,19 @@
     res.headers[b'Content-Type'] = b'text/plain; charset=utf-8'
     res.setbodybytes(b'')
 
+def _logexception(req):
+    """Write information about the current exception to wsgi.errors."""
+    tb = pycompat.sysbytes(traceback.format_exc())
+    errorlog = req.rawenv[r'wsgi.errors']
+
+    uri = b''
+    if req.apppath:
+        uri += req.apppath
+    uri += b'/' + req.dispatchpath
+
+    errorlog.write(b"Exception happened while processing request '%s':\n%s" %
+                   (uri, tb))
+
 def _processbatchrequest(repo, req, res):
     """Handle a request for the Batch API, which is the gateway to granting file
     access.
@@ -179,6 +193,8 @@
             verifies = store.verify(oid)
         except IOError as inst:
             if inst.errno != errno.ENOENT:
+                _logexception(req)
+
                 rsp['error'] = {
                     'code': 500,
                     'message': inst.strerror or 'Internal Server Server'