diff options
author | David Ferguson <ferguson.david@gmail.com> | 2013-06-19 07:40:32 -0400 |
---|---|---|
committer | Gerrit Code Review <gerrit@cyanogenmod.org> | 2013-07-03 12:56:41 -0700 |
commit | b8fddaca8ec0f4dd79bcb4660e1e4416e365a763 (patch) | |
tree | 530ddc583f64ce96e70e6490b819542473a06459 | |
parent | d0884b9808c44d6ea8c72c9e8f9e75e01eb303df (diff) | |
download | build-b8fddaca8ec0f4dd79bcb4660e1e4416e365a763.zip build-b8fddaca8ec0f4dd79bcb4660e1e4416e365a763.tar.gz build-b8fddaca8ec0f4dd79bcb4660e1e4416e365a763.tar.bz2 |
repopick: gracefully handle empty/non-JSON server responses
Change-Id: Idbabdbfb4a910de0ad405f02b2a84cf2bc9ef3dc
-rwxr-xr-x | tools/repopick.py | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/tools/repopick.py b/tools/repopick.py index 7336e78..ca1a4da 100755 --- a/tools/repopick.py +++ b/tools/repopick.py @@ -182,13 +182,25 @@ for change in args.change_number: print('Fetching from: %s\n' % url) f = urllib.request.urlopen(url) d = f.read().decode("utf-8") - - # Parse the result if args.verbose: print('Result from request:\n' + d) + + # Clean up the result d = d.split('\n')[1] + matchObj = re.match(r'\[\s*\]', d) + if matchObj: + sys.stderr.write('ERROR: Change number %s was not found on the server\n' % change) + sys.exit(1) d = re.sub(r'\[(.*)\]', r'\1', d) - data = json.loads(d) + + # Parse the JSON + try: + data = json.loads(d) + except ValueError: + sys.stderr.write('ERROR: The response from the server could not be parsed properly\n') + if not args.verbose: + sys.stderr.write('The malformed response was: %s\n' % d) + sys.exit(1) # Extract information from the JSON response project_name = data['project'] |