From a02f67f133a535e7c61172b1e81fd26660b164ae Mon Sep 17 00:00:00 2001 From: Olivier Mangin Date: Thu, 11 May 2017 15:49:09 -0400 Subject: [PATCH] Minor improvement of error handling. Also removes ignore of broken pipe from 5ca090668 since this is not handling it the right way (see #60). --- pubs/pubs | 16 ++-------------- pubs/pubs_cmd.py | 3 ++- pubs/uis.py | 9 ++++++--- 3 files changed, 10 insertions(+), 18 deletions(-) diff --git a/pubs/pubs b/pubs/pubs index de96fe2..7699f18 100755 --- a/pubs/pubs +++ b/pubs/pubs @@ -1,19 +1,7 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- -import sys - from pubs import pubs_cmd -try: - pubs_cmd.execute() -except BrokenPipeError: - # stdout or stderr has been closed, cleaning up - try: - sys.stdout.close() - except IOError: - pass - try: - sys.stderr.close() - except IOError: - pass + +pubs_cmd.execute() diff --git a/pubs/pubs_cmd.py b/pubs/pubs_cmd.py index c443f26..5b93893 100644 --- a/pubs/pubs_cmd.py +++ b/pubs/pubs_cmd.py @@ -84,4 +84,5 @@ def execute(raw_args=sys.argv): args.func(conf, args) except Exception as e: - uis.get_ui().handle_exception(e) + if not uis.get_ui().handle_exception(e): + raise diff --git a/pubs/uis.py b/pubs/uis.py index 7298e77..dfb5cd6 100644 --- a/pubs/uis.py +++ b/pubs/uis.py @@ -84,11 +84,14 @@ class PrintUI(object): sys.exit(error_code) def handle_exception(self, exc): - if self.debug: - raise - else: + """Attempts to handle exception. + + :returns: True if exception has been handled (currently never happens) + """ + if not self.debug: self.error(ustr(exc)) self.exit() + return False class InputUI(PrintUI):