Give more simple message when a SyntaxError is thrown
TEST=none, no big deal. I'll get a breakpad report otherwise anyway. This is solely to *reduce* the number of breakpad stack trace that this is done.
Review URL: http://codereview.chromium.org/2885020
git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@51739 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/gclient_utils.py b/gclient_utils.py
index 3297e63..54910ce 100644
--- a/gclient_utils.py
+++ b/gclient_utils.py
@@ -100,6 +100,23 @@
pass
+def SyntaxErrorToError(filename, e):
+ """Raises a gclient_utils.Error exception with the human readable message"""
+ try:
+ # Try to construct a human readable error message
+ if filename:
+ error_message = 'There is a syntax error in %s\n' % filename
+ else:
+ error_message = 'There is a syntax error\n'
+ error_message += 'Line #%s, character %s: "%s"' % (
+ e.lineno, e.offset, re.sub(r'[\r\n]*$', '', e.text))
+ except:
+ # Something went wrong, re-raise the original exception
+ raise e
+ else:
+ raise Error(error_message)
+
+
class PrintableObject(object):
def __str__(self):
output = ''