From 1bd1ed3cc63bc8cf9e3fe863161fb71d4f71a40b Mon Sep 17 00:00:00 2001 From: "maruel@chromium.org" Date: Wed, 24 Nov 2010 20:50:56 +0000 Subject: [PATCH] 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 --- breakpad.py | 38 ++++++++++++++++++++++++++++++-------- gclient_utils.py | 2 -- pylintrc | 3 ++- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/breakpad.py b/breakpad.py index f8f1a1b5a..21b13f801 100644 --- a/breakpad.py +++ b/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()) diff --git a/gclient_utils.py b/gclient_utils.py index 5ab1ed509..718284852 100644 --- a/gclient_utils.py +++ b/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: diff --git a/pylintrc b/pylintrc index 92da7be07..371ff4319 100644 --- a/pylintrc +++ b/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]