Index: gclient_utils.py |
diff --git a/gclient_utils.py b/gclient_utils.py |
index 3297e63872c20363d4810660c23160b95f55806c..54910ce45a2cfd482955e1cad31c70ec6a846d18 100644 |
--- a/gclient_utils.py |
+++ b/gclient_utils.py |
@@ -100,6 +100,23 @@ class Error(Exception): |
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 = '' |