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

Unified Diff: gclient_utils.py

Issue 2885020: Give more simple message when a SyntaxError is thrown (Closed)
Patch Set: Created 10 years, 5 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 | « gclient.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 = ''
« no previous file with comments | « gclient.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698