Minor improvement of error handling.
Also removes ignore of broken pipe from 5ca090668 since this is not handling it the right way (see #60).
This commit is contained in:
parent
d4c18ad1a4
commit
a02f67f133
16
pubs/pubs
16
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()
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
x
Reference in New Issue
Block a user