From 8fe8e00e1b3901b08494e78effd64470bc1c13ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radom=C3=ADr=20Bos=C3=A1k?= Date: Fri, 10 Mar 2017 17:54:02 +0100 Subject: [PATCH] Catch keyboard interrupt when opening journal (#476) If the journal is encrypted, jrnl asks for a password using the getpass.getpass function. If user presses the keyboard interrupt (e.g. ctrl+c) during the password prompt, jrnl crashes and prints a stack trace. This however is not very user friendly. This commit adds a check for KeyboardInterrupt Exception and prints a message whenever this exception occurs and exits. Stack is no longer printed. Fixes #450 --- jrnl/cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/jrnl/cli.py b/jrnl/cli.py index 49bbcb6a..72eff470 100644 --- a/jrnl/cli.py +++ b/jrnl/cli.py @@ -206,7 +206,11 @@ def run(manual_args=None): mode_compose = False # This is where we finally open the journal! - journal = Journal.open_journal(journal_name, config) + try: + journal = Journal.open_journal(journal_name, config) + except KeyboardInterrupt: + util.prompt("[Interrupted while opening journal]".format(journal_name)) + sys.exit(1) # Import mode if mode_import: