diff --git a/jrnl/editor.py b/jrnl/editor.py index c00c4073..7087f865 100644 --- a/jrnl/editor.py +++ b/jrnl/editor.py @@ -3,11 +3,8 @@ import os import subprocess import sys import tempfile -import textwrap from pathlib import Path -from jrnl.color import ERROR_COLOR -from jrnl.color import RESET_COLOR from jrnl.os_compat import on_windows from jrnl.os_compat import split_args from jrnl.output import print_msg @@ -30,15 +27,10 @@ def get_text_from_editor(config, template=""): try: subprocess.call(split_args(config["editor"]) + [tmpfile]) - except FileNotFoundError as e: - error_msg = f""" - {ERROR_COLOR}{str(e)}{RESET_COLOR} - - Please check the 'editor' key in your config file for errors: - {repr(config['editor'])} - """ - print(textwrap.dedent(error_msg).strip(), file=sys.stderr) - exit(1) + except FileNotFoundError: + raise JrnlException( + JrnlExceptionMessage.EditorMisconfigured, editor_key=config["editor"] + ) with open(tmpfile, "r", encoding="utf-8") as f: raw = f.read() diff --git a/jrnl/exception.py b/jrnl/exception.py index 3ec5666b..e9198dbd 100644 --- a/jrnl/exception.py +++ b/jrnl/exception.py @@ -44,6 +44,13 @@ class JrnlExceptionMessage(Enum): KeyboardInterrupt = "Aborted by user" + EditorMisconfigured = """ + No such file or directory: '{editor_key}' + + Please check the 'editor' key in your config file for errors: + editor: '{editor_key}' + """ + SomeTest = """ Some error or something