Added check for empty config file and if so, use default config

This commit is contained in:
Jonathan van der Steege 2022-04-27 17:07:57 +02:00
parent 602dad7e06
commit ca96e3175e
2 changed files with 11 additions and 1 deletions

View file

@ -75,6 +75,12 @@ def load_or_install_jrnl(alt_config_path):
logging.debug("Reading configuration from file %s", config_path) logging.debug("Reading configuration from file %s", config_path)
config = load_config(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): if is_old_version(config_path):
from jrnl import upgrade from jrnl import upgrade

View file

@ -85,7 +85,6 @@ Feature: Multiple journals
Then the output should contain "Journal encrypted to features/journals/basic_onefile.journal" Then the output should contain "Journal encrypted to features/journals/basic_onefile.journal"
And the config should contain "encrypt: false" And the config should contain "encrypt: false"
Scenario: Don't overwrite main config when decrypting a journal in an alternate config Scenario: Don't overwrite main config when decrypting a journal in an alternate config
Given the config "editor_encrypted.yaml" exists Given the config "editor_encrypted.yaml" exists
And we use the password "bad doggie no biscuit" if prompted 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" When we run "jrnl --cf editor_encrypted.yaml --decrypt"
Then the config should contain "encrypt: true" Then the config should contain "encrypt: true"
And the output should not contain "Wrong password" 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"