From e181302ca48364d30bda28ad03c6bbf2c3ce8acc Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 19 Feb 2022 17:31:59 -0800 Subject: [PATCH] add new exception handling to 'nothing saved to file' errors --- jrnl/editor.py | 2 +- jrnl/exception.py | 6 +++++- jrnl/jrnl.py | 2 +- tests/bdd/features/write.feature | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/jrnl/editor.py b/jrnl/editor.py index 7087f865..bdacfc7c 100644 --- a/jrnl/editor.py +++ b/jrnl/editor.py @@ -37,7 +37,7 @@ def get_text_from_editor(config, template=""): os.remove(tmpfile) if not raw: - print("[Nothing saved to file]", file=sys.stderr) + raise JrnlException(JrnlExceptionMessage.NoTextReceived) return raw diff --git a/jrnl/exception.py b/jrnl/exception.py index 2ab0956b..ae38e814 100644 --- a/jrnl/exception.py +++ b/jrnl/exception.py @@ -51,7 +51,11 @@ class JrnlExceptionMessage(Enum): NothingToDelete = """ No entries to delete, because the search returned no results. - """ + """ + + NoTextReceived = """ + Nothing saved to file. + """ UpgradeAborted = """ jrnl was NOT upgraded diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index a36025f4..1b2d2954 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -136,7 +136,7 @@ def write_mode(args, config, journal, **kwargs): if not raw: logging.error("Write mode: couldn't get raw text") - sys.exit() + raise JrnlException(JrnlExceptionMessage.NoTextReceived) logging.debug( 'Write mode: appending raw text to journal "%s": %s', args.journal_name, raw diff --git a/tests/bdd/features/write.feature b/tests/bdd/features/write.feature index 062c5fef..60f22002 100644 --- a/tests/bdd/features/write.feature +++ b/tests/bdd/features/write.feature @@ -78,7 +78,7 @@ Feature: Writing new entries. And we write nothing to the editor if opened And we use the password "test" if prompted When we run "jrnl --edit" - Then the error output should contain "[Nothing saved to file]" + Then the error output should contain "Nothing saved to file" And the editor should have been called Examples: configs