roomservice: Improve error handling on search
Use the relevant forms of 'except' for urllib and parsing instead of a
general except which was performed too late anyways.
Change-Id: Ia1fc89dd5a8a703fc0175aef7b6dd013a44a2c8e
diff --git a/tools/roomservice.py b/tools/roomservice.py
index 5eef4ee..241ea26 100755
--- a/tools/roomservice.py
+++ b/tools/roomservice.py
@@ -55,16 +55,15 @@
if not depsonly:
githubreq = urllib.request.Request("https://api.github.com/search/repositories?q=%s+user:CyanogenMod+in:name+fork:true" % device)
add_auth(githubreq)
- result = json.loads(urllib.request.urlopen(githubreq).read().decode())
try:
- numresults = int(result['total_count'])
- except:
- print("Failed to search GitHub (offline?)")
+ result = json.loads(urllib.request.urlopen(githubreq).read().decode())
+ except urllib.error.URLError:
+ print("Failed to search GitHub")
sys.exit()
- if (numresults == 0):
- print("Could not find device %s on github.com/CyanogenMod" % device)
+ except ValueError:
+ print("Failed to parse return data from GitHub")
sys.exit()
- for res in result['items']:
+ for res in result.get('items', []):
repositories.append(res)
local_manifests = r'.repo/local_manifests'