diff options
author | 2017-07-29 18:19:23 +0900 | |
---|---|---|
committer | 2017-07-29 18:19:23 +0900 | |
commit | cfea219eb445645bd2374ed14c67d305b2bfe1c0 (patch) | |
tree | 0590c92fe31045c0db8558aa896d6881d6d30128 | |
parent | catching client errors (diff) | |
download | elivepatch-cfea219eb445645bd2374ed14c67d305b2bfe1c0.tar.gz elivepatch-cfea219eb445645bd2374ed14c67d305b2bfe1c0.tar.bz2 elivepatch-cfea219eb445645bd2374ed14c67d305b2bfe1c0.zip |
cleaned error catching
Because we are going to implement new feature (incremental patch and cve)
to elivepatch, we need to catch errors for giving a clean output interface.
Useful for example when we need to give some more informative output toward
the user
-rw-r--r-- | elivepatch_client/client/restful.py | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/elivepatch_client/client/restful.py b/elivepatch_client/client/restful.py index f5b78cd..a5eefa5 100644 --- a/elivepatch_client/client/restful.py +++ b/elivepatch_client/client/restful.py @@ -61,9 +61,9 @@ class ManaGer(object): response_dict = response.json() except requests.exceptions.ConnectionError as e: print('connection error: %s' % e) + sys.exit(1) except: - e = sys.exc_info()[0] - print( "Error: %s" % e ) + self.catching_exceptions_exit(self.send_file) return response_dict def build_livepatch(self): @@ -76,8 +76,7 @@ class ManaGer(object): response = requests.post(url, json=payload) print(response.json()) except: - e = sys.exc_info()[0] - print( "Error build_livepatch: %s" % e ) + self.catching_exceptions_exit(self.build_livepatch) def get_livepatch(self): from io import BytesIO @@ -99,8 +98,7 @@ class ManaGer(object): print('livepatch not found') r.close() except: - e = sys.exc_info()[0] - print( "Error get livepatch: %s" % e ) + self.catching_exceptions_exit(self.get_livepatch) if os.path.exists('myfile.ko'): elivepatch_uuid_dir = os.path.join('..', 'elivepatch-'+ self.uuid) @@ -110,3 +108,8 @@ class ManaGer(object): print('livepatch saved in ' + elivepatch_uuid_dir + '/ folder') else: print('livepatch not received') + + def catching_exceptions_exit(self, current_function): + e = sys.exc_info() + print( "Error %s: %s" % (current_function.__name__, str(e)) ) + sys.exit(1)
\ No newline at end of file |