From fb20f2ffa281f385edbc9f5d0409ac8bed0d6662 Mon Sep 17 00:00:00 2001 From: apainintheneck Date: Mon, 25 Apr 2022 17:41:14 -0700 Subject: [PATCH] Display "Entry not saved" after empty entry on cmdline --- jrnl/jrnl.py | 8 +++----- jrnl/messages.py | 2 +- tests/bdd/features/write.feature | 18 ++++++++++++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 8014b628..f6715f76 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -134,11 +134,9 @@ def write_mode(args, config, journal, **kwargs): else: raw = _write_in_editor(config) - if not raw: - logging.error("Write mode: couldn't get raw text") - raise JrnlException( - Message(MsgText.JrnlExceptionMessage.NoTextReceived, MsgType.ERROR) - ) + if not raw or raw.isspace(): + logging.error("Write mode: couldn't get raw text or entry was empty") + raise JrnlException(Message(MsgText.NoTextReceived, MsgType.ERROR)) logging.debug( 'Write mode: appending raw text to journal "%s": %s', args.journal_name, raw diff --git a/jrnl/messages.py b/jrnl/messages.py index e6a1933a..d1edc2dc 100644 --- a/jrnl/messages.py +++ b/jrnl/messages.py @@ -98,7 +98,7 @@ class MsgText(Enum): """ NoTextReceived = """ - Nothing saved to file + Entry not saved """ # --- Upgrade --- # diff --git a/tests/bdd/features/write.feature b/tests/bdd/features/write.feature index 60f22002..6425a038 100644 --- a/tests/bdd/features/write.feature +++ b/tests/bdd/features/write.feature @@ -73,12 +73,12 @@ Feature: Writing new entries. | basic_dayone.yaml | | basic_folder.yaml | - Scenario Outline: Writing an empty entry from the editor should yield "Nothing saved to file" message + Scenario Outline: Writing an empty entry from the editor should yield "Entry not saved" message Given we use the config "" 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 "Entry not saved" And the editor should have been called Examples: configs @@ -89,6 +89,20 @@ Feature: Writing new entries. | basic_encrypted.yaml | | basic_onefile.yaml | + Scenario Outline: Writing an empty entry from the command line should yield "Entry not saved" message + Given we use the config "" + And we use the password "test" if prompted + When we run "jrnl" and enter "\x04" + Then the error output should contain "Entry not saved" + When we run "jrnl" and enter " \t \n \x04" + Then the error output should contain "Entry not saved" + + Examples: configs + | config_file | + | basic_onefile.yaml | + | basic_encrypted.yaml | + | basic_folder.yaml | + | basic_dayone.yaml | Scenario Outline: Writing an empty entry from the command line with no editor should yield nothing Given we use the config ""