def handle_unexpected_errors(f):
"""Decorator that catches unexpected errors."""
@wraps(f)
def call_f(*args, **kwargs):
try:
return f(*args, **kwargs)
except Exception as e:
errorf = StringIO()
print_exc(file=errorf)
error = errorf.getvalue()
click.echo(
"Looks like there's a bug in our code. Sorry about that!"
" Here's the traceback:\n" + error)
if click.confirm(
"Would you like to file an issue in our issue tracker?",
default=True, abort=True):
url = "https://github.com/datawire/pib/issues/new?body="
body = quote_plus(BUG_REPORT_TEMPLATE.format(
os.getcwd(), __version__, python_version,
run_result(["uname", "-a"]), error))
webbrowser.open_new(url + body)
return call_f
评论列表
文章目录