diff --git a/bebop/browser/browser.py b/bebop/browser/browser.py index 552a821..4b0851e 100644 --- a/bebop/browser/browser.py +++ b/bebop/browser/browser.py @@ -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() diff --git a/bebop/command_line.py b/bebop/command_line.py index 4138c62..8582072 100644 --- a/bebop/command_line.py +++ b/bebop/command_line.py @@ -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: diff --git a/bebop/external.py b/bebop/external.py index 334fd56..3b69afc 100644 --- a/bebop/external.py +++ b/bebop/external.py @@ -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