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

Unified Diff: gclient.py

Issue 113968: Add code to handle errors in .gclient configuration files (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools/
Patch Set: '' Created 11 years, 7 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: gclient.py
===================================================================
--- gclient.py (revision 17115)
+++ gclient.py (working copy)
@@ -940,7 +940,21 @@
def SetConfig(self, content):
self._config_dict = {}
self._config_content = content
- exec(content, self._config_dict)
+ try:
+ exec(content, self._config_dict)
+ except SyntaxError, e:
+ try:
+ # Try to construct a human readable error message
+ error_message = [
+ 'There is a syntax error in your configuration file.',
+ 'Line #%s, character %s:' % (e.lineno, e.offset),
+ '"%s"' % re.sub(r'[\r\n]*$', '', e.text) ]
+ except:
+ # Something went wrong, re-raise the original exception
+ raise e
+ else:
+ # Raise a new exception with the human readable message:
+ raise Error('\n'.join(error_message))
def SaveConfig(self):
FileWrite(os.path.join(self._root_dir, self._options.config_filename),
« 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