Report unahndled exceptions when starting loop in URL hints kitten

This commit is contained in:
Kovid Goyal 2018-03-08 12:58:54 +05:30
parent bc829a9712
commit dd128a99ac
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -171,6 +171,20 @@ def mark(finditer, line, index_map):
return line, marks 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): def run(args, source_file=None):
if source_file is None: if source_file is None:
text = sys.stdin.buffer.read().decode('utf-8') 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.')) input(_('No URLs found, press Enter to abort.'))
return return
loop = Loop() try:
handler = URLHints(lines, index_map) run_loop(args, lines, index_map)
loop.loop(handler) except Exception:
if handler.chosen and loop.return_code == 0: import traceback
cmd = command_for_open(args.program) traceback.print_exc()
ret = subprocess.Popen(cmd + [handler.chosen]).wait() input(_('Press Enter to quit'))
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)
OPTIONS = partial('''\ OPTIONS = partial('''\