From 94feae735e93db0f97a014814b6a0605f54c0278 Mon Sep 17 00:00:00 2001 From: Jonathan Wren Date: Sat, 19 Feb 2022 16:57:56 -0800 Subject: [PATCH] add new 'NothingToDelete' error to replace old behavior --- jrnl/exception.py | 4 ++++ jrnl/jrnl.py | 9 ++++----- tests/bdd/features/delete.feature | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/jrnl/exception.py b/jrnl/exception.py index 46a17e22..a8a94b48 100644 --- a/jrnl/exception.py +++ b/jrnl/exception.py @@ -53,6 +53,10 @@ class JrnlExceptionMessage(Enum): https://github.com/jrnl-org/jrnl/issues/new?title=JournalFailedUpgrade """ + NothingToDelete = """ + No entries to delete, because the search returned no results. + """ + UpgradeAborted = """ jrnl was NOT upgraded """ diff --git a/jrnl/jrnl.py b/jrnl/jrnl.py index 232eb702..fc79edb3 100644 --- a/jrnl/jrnl.py +++ b/jrnl/jrnl.py @@ -18,6 +18,9 @@ from .exception import UserAbort from . import time from .override import apply_overrides +from jrnl.exception import JrnlException +from jrnl.exception import JrnlExceptionMessage + def run(args): """ @@ -310,11 +313,7 @@ def _pluralize_entry(num): def _delete_search_results(journal, old_entries, **kwargs): if not journal.entries: - print( - "[No entries deleted, because the search returned no results.]", - file=sys.stderr, - ) - sys.exit(1) + raise JrnlException(JrnlExceptionMessage.NothingToDelete) entries_to_delete = journal.prompt_delete_entries() diff --git a/tests/bdd/features/delete.feature b/tests/bdd/features/delete.feature index cfbe08ee..423b60d3 100644 --- a/tests/bdd/features/delete.feature +++ b/tests/bdd/features/delete.feature @@ -41,6 +41,7 @@ Feature: Delete entries from journal Scenario Outline: Delete flag with nonsense input deletes nothing (issue #932) Given we use the config "" When we run "jrnl --delete asdfasdf" + Then the output should contain "NothingToDelete" When we run "jrnl -99 --short" Then the output should be 2020-08-29 11:11 Entry the first.