diff --git a/jrnl/install.py b/jrnl/install.py index 306b44e1..f8322fba 100644 --- a/jrnl/install.py +++ b/jrnl/install.py @@ -75,6 +75,10 @@ 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("Unable to parse config file", file=sys.stderr) + sys.exit() + 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..0bba7037 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,14 @@ 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: Show an error message when the config file is empty + Given we use the config "empty_file.yaml" + When we run "jrnl -1" + Then the error output should contain "Unable to parse config file" + + Scenario: Show an error message when using --config-file with empty file + Given the config "empty_file.yaml" exists + And we use the config "basic_onefile.yaml" + When we run "jrnl --cf empty_file.yaml" + Then the error output should contain "Unable to parse config file" diff --git a/tests/data/configs/empty_file.yaml b/tests/data/configs/empty_file.yaml new file mode 100644 index 00000000..e69de29b diff --git a/tests/lib/given_steps.py b/tests/lib/given_steps.py index ba619dba..dd7c4720 100644 --- a/tests/lib/given_steps.py +++ b/tests/lib/given_steps.py @@ -101,7 +101,11 @@ def we_use_the_config(request, temp_dir, working_dir): # @todo get rid of this by using default config values # merge in version number - if config_file.endswith("yaml") and os.path.exists(config_dest): + if ( + config_file.endswith("yaml") + and os.path.exists(config_dest) + and os.path.getsize(config_dest) > 0 + ): # Add jrnl version to file for 2.x journals with open(config_dest, "a") as cf: cf.write("version: {}".format(__version__))