Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Unified Diff: tools/telemetry/telemetry/core/exceptions.py

Issue 965063002: Telemtry: Add a method AddDebuggingMessage to Error. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@telemetry_make_new_exceptions3
Patch Set: Add more information about the stack trace. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/telemetry/telemetry/core/exceptions.py
diff --git a/tools/telemetry/telemetry/core/exceptions.py b/tools/telemetry/telemetry/core/exceptions.py
index ed9f9cbdf9d4ce8658a63df86fc98153139d4be9..6b13129f89ee9cf2e01919d953fd4a29dcd140d2 100644
--- a/tools/telemetry/telemetry/core/exceptions.py
+++ b/tools/telemetry/telemetry/core/exceptions.py
@@ -2,10 +2,39 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
+import sys
+
class Error(Exception):
"""Base class for Telemetry exceptions."""
- pass
+ def __init__(self, msg=''):
+ super(Error, self).__init__(msg)
+ self._debugging_messages = []
+
+ def AddDebuggingMessage(self, msg):
+ """Adds a message to the description of the exception.
+
+ Many Telemetry exceptions arise from failures in another application. These
+ failures are difficult to pinpoint. This method allows Telemetry classes to
+ append useful debugging information to the exception. This method also logs
+ information about the location from where it was called.
+ """
+ frame = sys._getframe(1)
+ line_number = frame.f_lineno
+ file_name = frame.f_code.co_filename
+ function_name = frame.f_code.co_name
+ call_site = '%s:%s %s' % (file_name, line_number, function_name)
+ annotated_message = '(%s) %s' % (call_site, msg)
+
+ self._debugging_messages.append(annotated_message)
+
+ def __str__(self):
+ divider = '\n' + '*' * 80 + '\n'
+ output = super(Error, self).__str__()
+ for message in self._debugging_messages:
+ output += divider
+ output += message
+ return output
class PlatformError(Error):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698