From ca96e3175eee87e4e25b1ca822edcaa5c8745d88 Mon Sep 17 00:00:00 2001 From: Jonathan van der Steege Date: Wed, 27 Apr 2022 17:07:57 +0200 Subject: [PATCH] Added check for empty config file and if so, use default config --- jrnl/install.py | 6 ++++++ tests/bdd/features/config_file.feature | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/jrnl/install.py b/jrnl/install.py index 306b44e1..b5ce9b33 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -75,6 +75,12 @@ def load_or_install_jrnl(alt_config_path): logging.debug("Reading configuration from file %s", config_path) config = load_config(config_path) + if config is None: + print( + f"Configuration file {config_path} is empty, now using default config" + ) + config = get_default_config() + if is_old_version(config_path): from jrnl import upgrade diff --git a/tests/bdd/features/config_file.feature b/tests/bdd/features/config_file.feature index 4f306b54..2eccdfca 100644 --- a/tests/bdd/features/config_file.feature +++ b/tests/bdd/features/config_file.feature @@ -85,7 +85,6 @@ Feature: Multiple journals Then the output should contain "Journal encrypted to features/journals/basic_onefile.journal" And the config should contain "encrypt: false" - Scenario: Don't overwrite main config when decrypting a journal in an alternate config Given the config "editor_encrypted.yaml" exists And we use the password "bad doggie no biscuit" if prompted @@ -93,3 +92,8 @@ Feature: Multiple journals When we run "jrnl --cf editor_encrypted.yaml --decrypt" Then the config should contain "encrypt: true" And the output should not contain "Wrong password" + + Scenario: Use default config when configuration file is empty or corrupt + Given the config "empty_file.yaml" exists + When we run "jrnl --cf empty_file.yaml" + Then the output should contain "empty, now using default config" \ No newline at end of file