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 subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
import tempfile
|
||||||
import textwrap
|
|
||||||
from pathlib import Path
|
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 on_windows
|
||||||
from jrnl.os_compat import split_args
|
from jrnl.os_compat import split_args
|
||||||
from jrnl.output import print_msg
|
from jrnl.output import print_msg
|
||||||
|
@ -30,15 +27,10 @@ def get_text_from_editor(config, template=""):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.call(split_args(config["editor"]) + [tmpfile])
|
subprocess.call(split_args(config["editor"]) + [tmpfile])
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError:
|
||||||
error_msg = f"""
|
raise JrnlException(
|
||||||
{ERROR_COLOR}{str(e)}{RESET_COLOR}
|
JrnlExceptionMessage.EditorMisconfigured, editor_key=config["editor"]
|
||||||
|
)
|
||||||
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)
|
|
||||||
|
|
||||||
with open(tmpfile, "r", encoding="utf-8") as f:
|
with open(tmpfile, "r", encoding="utf-8") as f:
|
||||||
raw = f.read()
|
raw = f.read()
|
||||||
|
|
|
@ -44,6 +44,13 @@ class JrnlExceptionMessage(Enum):
|
||||||
|
|
||||||
KeyboardInterrupt = "Aborted by user"
|
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 = """
|
SomeTest = """
|
||||||
Some error or something
|
Some error or something
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue