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
experimental/szager/collated-output
maruel@chromium.org 16 years ago
parent 73e2114e7d
commit 5990f9d536

@ -204,7 +204,10 @@ class Dependency(GClientKeywords):
'Var': var.Lookup,
'deps_os': {},
}
try:
exec(deps_content, global_scope, local_scope)
except SyntaxError, e:
gclient_utils.SyntaxErrorToError(filepath, e)
deps = local_scope.get('deps', {})
# load os specific dependencies if defined. these dependencies may
# override or extend the values defined by the 'deps' member.
@ -464,18 +467,7 @@ solutions = [
try:
exec(content, 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 gclient_utils.Error('\n'.join(error_message))
gclient_utils.SyntaxErrorToError('.gclient', e)
for s in config_dict.get('solutions', []):
try:
self.dependencies.append(Dependency(
@ -538,7 +530,10 @@ solutions = [
filename = os.path.join(self.root_dir(), self._options.entries_filename)
if not os.path.exists(filename):
return {}
try:
exec(gclient_utils.FileRead(filename), scope)
except SyntaxError, e:
gclient_utils.SyntaxErrorToError(filename, e)
return scope['entries']
def _EnforceRevisions(self):

@ -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 = ''

@ -20,6 +20,7 @@ class GclientUtilsUnittest(SuperMoxTestBase):
'GetNamedNodeText', 'GetNodeNamedAttributeText', 'IsUsingGit',
'PathDifference', 'ParseXML', 'PrintableObject', 'RemoveDirectory',
'SplitUrlRevision', 'SubprocessCall', 'SubprocessCallAndFilter',
'SyntaxErrorToError',
'errno', 'logging', 'os', 're', 'stat', 'subprocess', 'sys', 'time',
'xml',
]

Loading…
Cancel
Save