Improve exception handling

This commit is contained in:
Ivan R. 2022-09-30 13:34:44 +05:00
parent 5ac687cf74
commit 838389ba1e
No known key found for this signature in database
GPG key ID: 67AA0CE744B974B8

View file

@ -37,7 +37,13 @@ def edit_note(base_dir: str, note_date: date):
filename = f'{note_date.day:02}.txt' filename = f'{note_date.day:02}.txt'
path_to_file = os.path.join(workdir, filename) path_to_file = os.path.join(workdir, filename)
editor = os.environ.get('EDITOR', 'nano') 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__': if __name__ == '__main__':