changeset 42:ac949d2b268a

Add some error handling.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 05 Jul 2016 14:15:57 +0300
parents 9eadb97a2e98
children a331209e24fc
files multimerge.py
diffstat 1 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/multimerge.py	Tue Jul 05 14:11:26 2016 +0300
+++ b/multimerge.py	Tue Jul 05 14:15:57 2016 +0300
@@ -77,10 +77,18 @@
 
 ## Function for handling Google API credentials
 def gcm_get_credentials(mcfg):
-    store = oauth2client.file.Storage(mcfg.credential_file)
+    try:
+        store = oauth2client.file.Storage(mcfg.credential_file)
+    except Exception as e:
+            gcm_fatal("Failed to read credential file:\n{0}\n\nERROR: {1}\n".format(mcfg.credential_file, str(e)))
+
     credentials = store.get()
     if not credentials or credentials.invalid:
-        flow = client.flow_from_clientsecrets(mcfg.secret_file, mcfg.scope)
+        try:
+            flow = client.flow_from_clientsecrets(mcfg.secret_file, mcfg.scope)
+        except Exception as e:
+            gcm_fatal("Failed to fetch client secret:\n{0}\n\nERROR: {1}\n".format(mcfg.secret_file, str(e)))
+
         flow.user_agent = mcfg.app_name
         credentials = tools.run_flow(flow, store, mcfg)
     if not credentials or credentials.invalid: