From df0032c05702ca45492255d7fcc21a88dc75900d Mon Sep 17 00:00:00 2001 From: "skylined@chromium.org" Date: Fri, 29 May 2009 10:43:56 +0000 Subject: [PATCH] Add code to handle errors in .gclient configuration files and output human readble information rather than a raw exception stack. Review URL: http://codereview.chromium.org/113968 git-svn-id: svn://svn.chromium.org/chrome/trunk/tools/depot_tools@17179 0039d316-1c4b-4281-b951-d872f2087c98 --- gclient.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/gclient.py b/gclient.py index 8646f319d..694435cf5 100755 --- a/gclient.py +++ b/gclient.py @@ -940,7 +940,21 @@ class GClient(object): 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),