diff options
author | David Ferguson <ferguson.david@gmail.com> | 2013-06-19 07:40:32 -0400 |
---|---|---|
committer | Adnan Begovic <adnan@cyngn.com> | 2015-10-06 16:12:15 -0700 |
commit | 773dbeb5cc345cf9e34ddd5f848ddb78e95a0f7b (patch) | |
tree | 1ac24e2fe6ffe9e31fe4dd999a9241502360a03b /tools | |
parent | 2350df7a339472693f266cfa48d71b77ca399863 (diff) | |
download | build-773dbeb5cc345cf9e34ddd5f848ddb78e95a0f7b.tar.gz build-773dbeb5cc345cf9e34ddd5f848ddb78e95a0f7b.tar.bz2 build-773dbeb5cc345cf9e34ddd5f848ddb78e95a0f7b.zip |
repopick: gracefully handle empty/non-JSON server responses
Change-Id: Idbabdbfb4a910de0ad405f02b2a84cf2bc9ef3dc
Diffstat (limited to 'tools')
-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 7336e7837..ca1a4da5c 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'] |