replace sys.exit call with new exception handling

This commit is contained in:
Jonathan Wren 2022-03-12 14:47:28 -08:00
parent c5fc211ae9
commit 548ac582d9
2 changed files with 13 additions and 5 deletions

View file

@ -110,9 +110,9 @@ class MsgText(Enum):
https://github.com/jrnl-org/jrnl/issues/new?title=JournalFailedUpgrade
"""
UpgradeAborted = """
jrnl was NOT upgraded
"""
UpgradeAborted = "jrnl was NOT upgraded"
ImportAborted = "Entries were NOT imported"
# -- Config --- #
AltConfigNotFound = """

View file

@ -4,6 +4,11 @@
import sys
from jrnl.exception import JrnlException
from jrnl.messages import Message
from jrnl.messages import MsgText
from jrnl.messages import MsgType
class JRNLImporter:
"""This plugin imports entries from other jrnl files."""
@ -22,8 +27,11 @@ class JRNLImporter:
try:
other_journal_txt = sys.stdin.read()
except KeyboardInterrupt:
print("[Entries NOT imported into journal.]", file=sys.stderr)
sys.exit(0)
raise JrnlException(
Message(MsgText.KeyboardInterruptMsg, MsgType.ERROR),
Message(MsgText.ImportAborted, MsgType.WARNING),
)
journal.import_(other_journal_txt)
new_cnt = len(journal.entries)
print(