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 https://github.com/jrnl-org/jrnl/issues/new?title=JournalFailedUpgrade
""" """
UpgradeAborted = """ UpgradeAborted = "jrnl was NOT upgraded"
jrnl was NOT upgraded
""" ImportAborted = "Entries were NOT imported"
# -- Config --- # # -- Config --- #
AltConfigNotFound = """ AltConfigNotFound = """

View file

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