From 838389ba1e05b7bcd10e34990713f49c0d2ea712 Mon Sep 17 00:00:00 2001 From: Ivan Reshetnikov Date: Fri, 30 Sep 2022 13:34:44 +0500 Subject: [PATCH] Improve exception handling --- histd.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/histd.py b/histd.py index 3783ff0..d2dcdff 100755 --- a/histd.py +++ b/histd.py @@ -37,7 +37,13 @@ def edit_note(base_dir: str, note_date: date): filename = f'{note_date.day:02}.txt' path_to_file = os.path.join(workdir, filename) editor = os.environ.get('EDITOR', 'nano') - subprocess.run([editor, path_to_file], check=True, cwd=base_dir) + try: + subprocess.run([editor, path_to_file], check=True, cwd=base_dir) + except FileNotFoundError: + print("Error: I can't find your text editor") + print("Make sure the 'EDITOR' environment variable is set correctly") + except subprocess.CalledProcessError: + print("Your editor returned non-zero exit code") if __name__ == '__main__':