external: do not crash if command can't be found

This commit is contained in:
dece 2021-06-03 19:08:54 +02:00
parent 0a05d75e6b
commit 52716e66a7
3 changed files with 18 additions and 3 deletions

View file

@ -675,7 +675,10 @@ class Browser:
return
command = self.config["source_editor"] + [source_filename]
open_external_program(command)
success = open_external_program(command)
if not success:
self.set_status_error("Could not open editor.")
if delete_source_after:
os.unlink(source_filename)
self.refresh_windows()

View file

@ -200,7 +200,9 @@ class CommandLine:
return
command = self.editor_command + [temp_filepath]
open_external_program(command)
success = open_external_program(command)
if not success:
return
try:
with open(temp_filepath, "rt") as temp_file:

View file

@ -1,6 +1,7 @@
"""Call external commands."""
import curses
import logging
import subprocess
@ -9,12 +10,21 @@ def open_external_program(command):
The caller has to refresh whatever windows it manages after calling this
method or garbage may be left on the screen.
Returns:
True if no exception occured.
"""
curses.nocbreak()
curses.echo()
curses.curs_set(1)
subprocess.run(command)
result = True
try:
subprocess.run(command)
except OSError as exc:
logging.error(f"Failed to run '{command}': {exc}")
result = False
curses.mousemask(curses.ALL_MOUSE_EVENTS)
curses.curs_set(0)
curses.noecho()
curses.cbreak()
return result