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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « gclient.py ('k') | tests/gclient_utils_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2009 Google Inc. All Rights Reserved. 1 # Copyright 2009 Google Inc. All Rights Reserved.
2 # 2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); 3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License. 4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at 5 # You may obtain a copy of the License at
6 # 6 #
7 # http://www.apache.org/licenses/LICENSE-2.0 7 # http://www.apache.org/licenses/LICENSE-2.0
8 # 8 #
9 # Unless required by applicable law or agreed to in writing, software 9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, 10 # distributed under the License is distributed on an "AS IS" BASIS,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 return None 93 return None
94 assert len(child_nodes) == 1 94 assert len(child_nodes) == 1
95 return child_nodes[0].getAttribute(attribute_name) 95 return child_nodes[0].getAttribute(attribute_name)
96 96
97 97
98 class Error(Exception): 98 class Error(Exception):
99 """gclient exception class.""" 99 """gclient exception class."""
100 pass 100 pass
101 101
102 102
103 def SyntaxErrorToError(filename, e):
104 """Raises a gclient_utils.Error exception with the human readable message"""
105 try:
106 # Try to construct a human readable error message
107 if filename:
108 error_message = 'There is a syntax error in %s\n' % filename
109 else:
110 error_message = 'There is a syntax error\n'
111 error_message += 'Line #%s, character %s: "%s"' % (
112 e.lineno, e.offset, re.sub(r'[\r\n]*$', '', e.text))
113 except:
114 # Something went wrong, re-raise the original exception
115 raise e
116 else:
117 raise Error(error_message)
118
119
103 class PrintableObject(object): 120 class PrintableObject(object):
104 def __str__(self): 121 def __str__(self):
105 output = '' 122 output = ''
106 for i in dir(self): 123 for i in dir(self):
107 if i.startswith('__'): 124 if i.startswith('__'):
108 continue 125 continue
109 output += '%s = %s\n' % (i, str(getattr(self, i, ''))) 126 output += '%s = %s\n' % (i, str(getattr(self, i, '')))
110 return output 127 return output
111 128
112 129
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
347 config_path = FindFileUpwards(config_file, path) 364 config_path = FindFileUpwards(config_file, path)
348 365
349 if not config_path: 366 if not config_path:
350 print "Can't find %s" % config_file 367 print "Can't find %s" % config_file
351 return None 368 return None
352 369
353 env = {} 370 env = {}
354 execfile(config_path, env) 371 execfile(config_path, env)
355 config_dir = os.path.dirname(config_path) 372 config_dir = os.path.dirname(config_path)
356 return config_dir, env['entries'] 373 return config_dir, env['entries']
OLDNEW
« 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