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

exec
dece 3 years ago
parent 0a05d75e6b
commit 52716e66a7

@ -675,7 +675,10 @@ class Browser:
return return
command = self.config["source_editor"] + [source_filename] 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: if delete_source_after:
os.unlink(source_filename) os.unlink(source_filename)
self.refresh_windows() self.refresh_windows()

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

@ -1,6 +1,7 @@
"""Call external commands.""" """Call external commands."""
import curses import curses
import logging
import subprocess import subprocess
@ -9,12 +10,21 @@ def open_external_program(command):
The caller has to refresh whatever windows it manages after calling this The caller has to refresh whatever windows it manages after calling this
method or garbage may be left on the screen. method or garbage may be left on the screen.
Returns:
True if no exception occured.
""" """
curses.nocbreak() curses.nocbreak()
curses.echo() curses.echo()
curses.curs_set(1) 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.mousemask(curses.ALL_MOUSE_EVENTS)
curses.curs_set(0) curses.curs_set(0)
curses.noecho() curses.noecho()
curses.cbreak() curses.cbreak()
return result

Loading…
Cancel
Save