From dd128a99ac4aab1e2a9ae5ec1fe91e9a73a838c9 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 8 Mar 2018 12:58:54 +0530 Subject: [PATCH] Report unahndled exceptions when starting loop in URL hints kitten --- kittens/url_hints/main.py | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/kittens/url_hints/main.py b/kittens/url_hints/main.py index ede34e4ca..fd9cdf7db 100644 --- a/kittens/url_hints/main.py +++ b/kittens/url_hints/main.py @@ -171,6 +171,20 @@ def mark(finditer, line, index_map): return line, marks +def run_loop(args, lines, index_map): + loop = Loop() + handler = URLHints(lines, index_map) + loop.loop(handler) + if handler.chosen and loop.return_code == 0: + cmd = command_for_open(args.program) + ret = subprocess.Popen(cmd + [handler.chosen]).wait() + if ret != 0: + print('URL handler "{}" failed with return code: {}'.format(' '.join(cmd), ret), file=sys.stderr) + input('Press Enter to quit') + loop.return_code = ret + raise SystemExit(loop.return_code) + + def run(args, source_file=None): if source_file is None: text = sys.stdin.buffer.read().decode('utf-8') @@ -195,17 +209,12 @@ def run(args, source_file=None): input(_('No URLs found, press Enter to abort.')) return - loop = Loop() - handler = URLHints(lines, index_map) - loop.loop(handler) - if handler.chosen and loop.return_code == 0: - cmd = command_for_open(args.program) - ret = subprocess.Popen(cmd + [handler.chosen]).wait() - if ret != 0: - print('URL handler "{}" failed with return code: {}'.format(' '.join(cmd), ret), file=sys.stderr) - input('Press Enter to quit') - loop.return_code = ret - raise SystemExit(loop.return_code) + try: + run_loop(args, lines, index_map) + except Exception: + import traceback + traceback.print_exc() + input(_('Press Enter to quit')) OPTIONS = partial('''\