Browse Source

Add more exception information to breakpad.

When an HTTP exception information is logged, no information is sent by
default. Add an helper function to manually extract interesting information
to append it to the exception type.

Also disable another pylint warning.

TEST=manual test
BUG=none

Review URL: http://codereview.chromium.org/5303002

git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@67306 0039d316-1c4b-4281-b951-d872f2087c98
maruel@chromium.org 14 years ago
parent
commit
1bd1ed3cc6
3 changed files with 32 additions and 11 deletions
  1. 30 8
      breakpad.py
  2. 0 2
      gclient_utils.py
  3. 2 1
      pylintrc

+ 30 - 8
breakpad.py

@@ -27,6 +27,34 @@ DEFAULT_URL = 'https://chromium-status.appspot.com/breakpad'
 _REGISTERED = False
 
 
+def FormatException(e):
+  """Returns a human readable form of an exception.
+
+  Adds the maximum number of interesting information in the safest way."""
+  try:
+    out = repr(e)
+  except Exception:
+    out = ''
+  try:
+    out = str(e)
+    if isinstance(e, Exception):
+      # urllib exceptions, usually the HTTP headers.
+      if hasattr(e, 'headers'):
+        out += '\nHeaders: %s' % e.headers
+      if hasattr(e, 'url'):
+        out += '\nUrl: %s' % e.url
+      if hasattr(e, 'msg'):
+        out += '\nMsg: %s' % e.msg
+      # The web page in some urllib exceptions.
+      if hasattr(e, 'read') and callable(e.read):
+        out += '\nread(): %s' % e.read()
+      if hasattr(e, 'info') and callable(e.info):
+        out += '\ninfo(): %s' % e.info()
+  except Exception:
+    pass
+  return out
+
+
 def SendStack(last_tb, stack, url=None):
   """Sends the stack trace to the breakpad server."""
   if not url:
@@ -35,19 +63,13 @@ def SendStack(last_tb, stack, url=None):
   try:
     params = {
         'args': sys.argv,
-        'stack': stack,
+        'stack': stack[0:4096],
         'user': getpass.getuser(),
-        'exception': last_tb,
+        'exception': FormatException(last_tb),
         'host': socket.getfqdn(),
         'cwd': os.getcwd(),
     }
-    # No exception type(s) specified
     # pylint: disable=W0702
-    try:
-      # That may not always work.
-      params['exception'] = str(last_tb)
-    except:
-      pass
     print('\n'.join('  %s: %s' % (k, v[0:50]) for k, v in params.iteritems()))
     request = urllib.urlopen(url, urllib.urlencode(params))
     print(request.read())

+ 0 - 2
gclient_utils.py

@@ -701,8 +701,6 @@ class ExecutionQueue(object):
       """Runs in its own thread."""
       logging.debug('running(%s)' % self.item.name)
       work_queue = self.kwargs['work_queue']
-      # It's necessary to catch all exceptions.
-      # pylint: disable=W0703
       try:
         self.item.run(*self.args, **self.kwargs)
       except Exception:

+ 2 - 1
pylintrc

@@ -56,8 +56,9 @@ load-plugins=
 # W0511: TODO
 # W0603: Using the global statement
 # W0613: Unused argument ''
+# W0703: Catch "Exception"
 # W6501: Specify string format arguments as logging function parameters
-disable=C0103,C0111,C0302,I0011,R0401,R0801,R0901,R0902,R0903,R0911,R0912,R0913,R0914,R0915,W0122,W0141,W0142,W0402,W0511,W0603,W0613,W6501
+disable=C0103,C0111,C0302,I0011,R0401,R0801,R0901,R0902,R0903,R0911,R0912,R0913,R0914,R0915,W0122,W0141,W0142,W0402,W0511,W0603,W0613,W0703,W6501
 
 
 [REPORTS]