Skip to content

Commit

Permalink
Display "No entry to save, because no text was received" after empty …
Browse files Browse the repository at this point in the history
…entry on cmdline (#1459)

* Display "Entry not saved" after empty entry on cmdline
* update error message
  • Loading branch information
apainintheneck committed Apr 30, 2022
1 parent d21398e commit d6d6db0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
8 changes: 3 additions & 5 deletions jrnl/jrnl.py
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion jrnl/messages.py
Expand Up @@ -98,7 +98,7 @@ def __str__(self) -> str:
"""

NoTextReceived = """
Nothing saved to file
No entry to save, because no text was received
"""

# --- Upgrade --- #
Expand Down
18 changes: 16 additions & 2 deletions tests/bdd/features/write.feature
Expand Up @@ -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 "No entry to save" message
Given we use the config "<config_file>"
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 "No entry to save, because no text was received"
And the editor should have been called

Examples: configs
Expand All @@ -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 "No entry to save" message
Given we use the config "<config_file>"
And we use the password "test" if prompted
When we run "jrnl" and enter "\x04"
Then the error output should contain "No entry to save, because no text was received"
When we run "jrnl" and enter " \t \n \x04"
Then the error output should contain "No entry to save, because no text was received"

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 "<config_file>"
Expand Down

0 comments on commit d6d6db0

Please sign in to comment.