mirror of
https://github.com/jrnl-org/jrnl.git
synced 2025-05-17 19:48:31 +02:00
udpate error to use new exception handling
This commit is contained in:
parent
66bdd06c51
commit
2d8ffd1174
2 changed files with 11 additions and 12 deletions
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue